添加formbuilder插件:
Composer应用
composer require kris/laravel-form-builder
下载成功
修改配置文件
在config/app.php
‘providers’ => [
代码语言:javascript复制 KrisLaravelFormBuilderFormBuilderServiceProvider::class,
]
‘aliases’ =>[
代码语言:javascript复制 'FormBuilder' => KrisLaravelFormBuilderFacadesFormbuilder::class,
]
创建form
Php artisan make:form Forms/名字–fields =“name:text,intro:text”
生成的文件
代码语言:javascript复制public function buildForm()
{
$this ->add('name', 'text', [ 'rules' => 'required|min:5' ]) ->add('lyrics', 'textarea', [ 'rules' => 'max:5000' ]); }
创建一个空的form
Php artisan make:form Forms/名字
代码语言:javascript复制public function buildForm()
{
}
控制器
引用:
代码语言:javascript复制use KrisLaravelFormBuilderFormBuilder;
函数:
代码语言:javascript复制public function create(FormBuilder $formBuilder){ $form = $formBuilder->create(AppFormPostForm::class,[ 'method' => 'POST', 'url' => route('photo.store') ]); return view('Photo.form',compact('form')); }
视图:
代码语言:javascript复制<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> {!! form($form) !!} </body> </html>
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113276.html原文链接:https://javaforall.cn