0 Star 0 Fork 0

IT大叔 / laravel-admin-plus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
form.md 5.63 KB
一键复制 编辑 原始数据 按行查看 历史
leno 提交于 2017-06-23 15:23 . 首次上传

Form

Encore\Admin\Widgets\Form class is used to quickly build a form:


$form = new Form();

$form->action('example');

$form->email('email')->default('qwe@aweq.com');
$form->password('password');
$form->text('name');
$form->url('url');
$form->color('color');
$form->map('lat', 'lng');
$form->date('date');
$form->json('val');
$form->dateRange('created_at', 'updated_at');

echo $form->render();

Form::__construct($data = []) generates a form object. If the $data parameter is passed, the elements in the $data array will be filled into the form.

Form::action($uri) method is used to set the form submission address.

Form::method($method) method is used to set the submit method of the form form, the default is POST method.

The form elements

The Form object implements nearly 30 form elements via the magic method __call(), which adds the form element with a short call:

Text input

$form->text($column, [$label]);

// Add a submission validation rule
$form->text($column, [$label])->rules('required|min:10');

Select

$form->select($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']);

Multiple select

$form->multipleSelect($column[, $label])->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']);

Textarea

$form->textarea($column[, $label]);

Radio

$form->radio($column[, $label])->values(['m' => 'Female', 'f'=> 'Male'])->default('m');

Checkbox

The values() method is used to set options:

$form->checkbox($column[, $label])->values([1 => 'foo', 2 => 'bar', 'val' => 'Option name']);

Email

$form->email($column[, $label]);

Password

$form->password($column[, $label]);

Url

$form->url($column[, $label]);

Ip

$form->ip($column[, $label]);

Mobile

$form->mobile($column[, $label])->format('999 9999 9999');

Color

$form->color($column[, $label])->default('#ccc');

Time

$form->time($column[, $label]);

// 设置时间格式,更多格式参考http://momentjs.com/docs/#/displaying/format/
$form->time($column[, $label])->format('HH:mm:ss');

Date

$form->date($column[, $label]);

// 设置日期格式,更多格式参考http://momentjs.com/docs/#/displaying/format/
$form->date($column[, $label])->format('YYYY-MM-DD');

Datetime

$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

$startTime$endTime is the start and end time fields:

$form->timeRange($startTime, $endTime, 'Time Range');

Date range

$startDate$endDate is the start and end date fields:

$form->dateRange($startDate, $endDate, 'Date Range');

Datetime range

$startDateTime$endDateTimeis the start and end datetime fields:

$form->datetimeRange($startDateTime, $endDateTime, 'DateTime Range');

Currency

$form->currency($column[, $label]);

// Sets the unit symbol
$form->currency($column[, $label])->symbol('¥');

Number

$form->number($column[, $label]);

Decimal

$form->decimal($column[, $label]);

Rate

$form->rate($column[, $label]);

Image upload

You can use compression, crop, add watermarks and other methods, please refer to [Intervention],The image upload directory is configured in upload in the file config/admin.php. If the directory does not exist, it needs to be created and write-enabled. :

$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');

File upload

文件上传目录在文件config/admin.php中的upload.file中配置,如果目录不存在,需要创建该目录并开放写权限。 The file upload directory is configured in upload in the file config/admin.php. If the directory does not exist, create the directory and open the write permissions.

$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');

Map

Map element is used to select the latitude and longitude, $latitude,$longitude for the latitude and longitude field, using Tencent map if the locale in config/app.php is set to zh_CN,otherwise use Google Maps:

$form->map($latitude, $longitude, $label);

// Use Tencent map
$form->map($latitude, $longitude, $label)->useTencentMap();

// Use Google Maps
$form->map($latitude, $longitude, $label)->useGoogleMap();

Slider

Can be used to select the type of digital fields, such as age:

$form->slider($column[, $label])->options(['max' => 100, 'min' => 1, 'step' => 1, 'postfix' => 'years old']);

Editor

$form->editor($column[, $label]);

Json Editor

$form->json($column[, $label]);

Hidden

$form->hidden($column);

Switch

on and off pairs of switches with the values 1 and 0:

$form->switch($column[, $label])->states(['on' => 1, 'off' => 0]);

Display

Only the fields are displayed without any action:

$form->display($column[, $label]);

Divide line

$form->divide();
PHP
1
https://gitee.com/itdashu/laravel-admin-plus.git
git@gitee.com:itdashu/laravel-admin-plus.git
itdashu
laravel-admin-plus
laravel-admin-plus
master

搜索帮助