添加formbuilder插件:
Composer应用
composer require kris/laravel-form-builder
下载成功
修改配置文件
在config/app.php
‘providers’ => [
Kris\LaravelFormBuilder\FormBuilderServiceProvider::class,
]
‘aliases’ =>[
'FormBuilder' => Kris\LaravelFormBuilder\Facades\Formbuilder::class,
]
创建form
Php artisan make:form Forms/名字–fields =“name:text,intro:text”
生成的文件
public function buildForm() { $this ->add('name', 'text', [ 'rules' => 'required|min:5' ]) ->add('lyrics', 'textarea', [ 'rules' => 'max:5000' ]); }
创建一个空的form
Php artisan make:form Forms/名字
public function buildForm() { }
控制器
引用:
use Kris\LaravelFormBuilder\FormBuilder;
函数:
public function create(FormBuilder $formBuilder){ $form = $formBuilder->create(\App\Form\PostForm::class,[ 'method' => 'POST', 'url' => route('photo.store') ]); return view('Photo.form',compact('form')); }
视图:
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> {!! form($form) !!} </body> </html>
评论(0)