$form->text($column, [$label]);// Add a submission validation rule$form->text($column, [$label])->rules('required|min:10');// Set FontAwesome icon$form->text($column, [$label])->icon('fa-pencil');// Set datalist$form->text($column, [$label])->datalist(['key'=>'value']);// Set inputmask, see https://github.com/RobinHerbots/Inputmask$form->text('code')->inputmask(['mask'=>'99-9999999']);
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 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:
classPostextendsModel public function getTagsAttribute($value) {returnexplode(',', $value); }publicfunctionsetTagsAttribute($value) {$this->attributes['tags'] =implode(',', $value); }}
If have too many options, you can load option by ajax
$form->checkbox($column[, $label])->options([1=>'foo',2=>'bar','val'=>'Option name']);$form->checkbox($column[, $label])->options([1=>'foo',2=>'bar','val'=>'Option name'])->stacked();// Setting options through closures$form->checkbox($column[, $label])->options(function () {return [1=>'foo',2=>'bar','val'=>'Option name'];});// If there are too many options, you can add a full checkbox to it.$form->checkbox($column[, $label])->options([])->canCheckAll();
$form->time($column[, $label]);// Set the time format, more formats reference http://momentjs.com/docs/#/displaying/format/ $form->time($column[, $label])->format('HH:mm:ss');
Date input
$form->date($column[, $label]);// Date format setting,more format please see http://momentjs.com/docs/#/displaying/format/$form->date($column[, $label])->format('YYYY-MM-DD');
Datetime input
$form->datetime($column[, $label]);// Set the date format, more format reference http://momentjs.com/docs/#/displaying/format/$form->datetime($column[, $label])->format('YYYY-MM-DD HH:mm:ss');
Time range select
$startTime、$endTimeis the start and end time fields:
$form->currency($column[, $label]);// set the unit symbol$form->currency($column[, $label])->symbol('¥');
Number input
$form->number($column[, $label]);// set max value$form->number($column[, $label])->max(100);// set min value$form->number($column[, $label])->min(10);
Rate input
$form->rate($column[, $label]);
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.phpUpload.image configuration, if the directory does not exist, you need to create the directory and open write permissions:
$form->image($column[, $label]);// Modify the image upload path and file name$form->image($column[, $label])->move($dir, $name);// Crop picture$form->image($column[, $label])->crop(int $width,int $height, [int $x,int $y]);// Add a watermark$form->image($column[, $label])->insert($watermark,'center');// add delete button$form->image($column[, $label])->removable();// Keep pictures when deleting data$form->image($column[, $label])->retainable();
Generate thumbnails after uploading images
// Generate thumbnails while uploading images$form->image($column[, $label])->thumbnail('small', $width =300, $height =300);// Or multiple thumbnails$form->image($column[, $label])->thumbnail(['small'=> [100,100],'small'=> [200,200],'small'=> [300,300],]);
Use thumbnails in models
classPhotoextendsModel{use\Ezadev\Admin\Traits\Resizable;}// To access thumbnail$photo->thumbnail('small','photo_column');
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.
$form->file($column[, $label]);// Modify the file upload path and file name$form->file($column[, $label])->move($dir, $name);// And set the upload file type$form->file($column[, $label])->rules('mimes:doc,docx,xlsx');// add delete button$form->file($column[, $label])->removable();// Keep files when deleting data$form->file($column[, $label])->retainable();// Add a download button, click to download$form->file($column[, $label])->downloadable();
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:
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:
$form->map($latitude, $longitude, $label);// Use Tencent map$form->map($latitude, $longitude, $label)->useTencentMap();// Use google map$form->map($latitude, $longitude, $label)->useGoogleMap();
Slider
Can be used to select the type of digital fields, such as age:
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.
$form->editor($column[, $label]);
Hidden field
$form->hidden($column);
Switch
On and Off pairs of switches with the values 1 and0:
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:
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:
$form->list('list');// Set the verification rules$form->list('list')->rules('required|min:5'));// set the maximum and minimum number of elements$form->list('list')->max(10)->min(5);
In the model you need to set the json cast of this field:
Protected $casts = ['list'=>'json', ];
KeyValue
Used to set the key-value array in JSON format:
$form->keyValue('kv');// Set the verification rules$form->keyValue('kv')->rules('required|min:5'));
In the model you need to set the json cast of this field: