Form Field
There are a lots of form components built into the model-form to help you quickly build forms.
Public methods
Set the value to save
$form->text('title')->value('text...');Set default value
$form->text('title')->default('text...');Set help message
$form->text('title')->help('help...');Set attributes of field element
$form->text('title')->attribute(['data-title' => 'title...']);
$form->text('title')->attribute('data-title', 'title...');Set placeholder
$form->text('title')->placeholder('Please input...');Set required
Setting pattern
Setting readonly
Setting disable
Setting autofocus
Model-form-tab
If the form contains too many fields, will lead to form page is too long, in which case you can use the tab to separate the form:
Text input
Select
If have too many options, you can load option by ajax:
The controller method for api /admin/api/users is:
The json returned from api /admin/demo/options:
Cascading select
select component supports one-way linkage of parent-child relationship:
Where load('city', '/api/city'); means that, after the current select option is changed, the current option will call the api /api/city via the argumentq api returns the data to fill the options for the city selection box, where api /api/city returns the data format that must match:
The code for the controller action is as follows:
Multiple select
You can store value of multiple select in two ways, one is many-to-many relation.
The second is to store the option array into a single field. If the field is a string type, it is necessary to define accessor and Mutator for the field.
For example, the field tags is stored as a string and separated by a comma ,, then its accessors and modifiers are defined as follows:
If have too many options, you can load option by ajax
The controller method for api /admin/api/users is:
The json returned from api /admin/demo/options:
Listbox
The usage is as same as mutipleSelect.
Textarea
Radio
Checkbox
checkbox can store values in two ways, seemultiple select
The options() method is used to set options:
Email input
Password input
URL input
Ip input
Phone number input
Color selector
Time input
Date input
Datetime input
Time range select
$startTime、$endTimeis the start and end time fields:
Date range select
$startDate、$endDateis the start and end date fields:
Datetime range select
$startDateTime、$endDateTime is the start and end datetime fields:
Currency input
Number input
Rate input
Image upload
Before use upload field, you must complete upload configuration, see image/file upload.
You can use compression, crop, add watermarks and other methods, please refer to [Intervention], picture upload directory in the file config / admin.php Upload.image configuration, if the directory does not exist, you need to create the directory and open write permissions:
Generate thumbnails after uploading images
Use thumbnails in models
File upload
Before use upload field, you must complete upload configuration, see image/file upload.
The file upload directory is configured in upload.file in the file config/admin.php. If the directory does not exist, it needs to be created and write-enabled.
Multiple image/file upload
The type of data submitted from multiple image/file field is array, if you the type of column in mysql table is array, or use mongodb, then you can save the array directly, but if you use string type to store the array data ,you need to specify a string format, For example, if you want to use json string to store the array data, you need to define a mutator for the column in model mutator, such as the field named pictures, define mutator:
Of course, you can also specify any other format.
Map
The map component has been deprecated and will be removed in a later release. Please use Latitude and longitude selector plugin extension instead.
The map field refers to the network resource, and if there is a problem with the network refer to form Component Management to remove the component.
Used to select the latitude and longitude, $ latitude,$ longitude for the latitude and longitude field, using Tencent map when locale set of laravel iszh_CN, otherwise use Google Maps:
Slider
Can be used to select the type of digital fields, such as age:
More options please ref to https://github.com/IonDen/ion.rangeSlider#settings
Rich text editor
The editor field refers to the network resource, and if there is a problem with the network refer to form Component Management to remove the component.
Hidden field
Switch
On and Off pairs of switches with the values 1 and0:
Display field
Only display the fields and without any action:
Divider
Html
insert html,the argument passed in could be objects which impletements Htmlable、Renderable, or has method __toString()
Tags
Insert the comma (,) separated string tags
Icon
Select the font-awesome icon.
Timezone
table

If a field stores a two-dimensional array in the json format, you can use the table form component to implement fast editing:
Also add accessor and mutator to this field in the model:
This component is similar to the hasMany component, but is used to handle a single field, suitable for simple two-dimensional data.
HasMany
One-to-many built-in tables for dealing with one-to-many relationships. Here is a simple example:
There are two tables are one-to-many relationship:
The model of tables are:
Build the form code as follows:
Embeds
Used to handle the JSON type field data of mysql or object type data of mongodb, or the data values of multiple fields can be stored in the form of theJSON string in the character type of mysql
Such as the extra column of the JSON or string type in the orders table, used to store data for multiple fields:
And then use in the form:
Callback function inside the form element to create the method call and the outside is the same.
List
A one-dimensional array used to set the JSON format:
In the model you need to set the json cast of this field:
KeyValue
Used to set the key-value array in JSON format:
In the model you need to set the json cast of this field:
Last updated