Laravel Form-builder使用

2022-07-07 11:29:08 浏览数 (1)

添加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

0 人点赞