laravel 5.4: From is gone. What is the new way to

2019-08-02 20:18发布

Doing something in a blade with Form in a new laravel 5.4 project, e.g.

{{ Form::hidden('data-name', $value->name) }}

will throw:

Class 'Form' not found

There are many posts with ways to try to fix this (many different and conflicting answers, some with several files needing to be edited and commands run), but my question is what is the new "correct" way to manipulate the form in laravel 5.x, seeing as it has been dropped (and adding back is non trivial)?

Currently, I have resorted to this option for laravel 5+:

<input type="hidden" name="token" value="{{ app('request')->input('token') }}">

标签: forms laravel
2条回答
Juvenile、少年°
2楼-- · 2019-08-02 20:47

Laravel externalized the management of Forms, Here is the package that implements it the way it used to be ( {{ Form::open() }} ), ( {{ Form::close() }} ) etc. All the fields are in the documentation.

查看更多
放荡不羁爱自由
3楼-- · 2019-08-02 20:47

Run the following command

composer require "laravelcollective/html":"^5.4.0"

Next, add your new provider to the providers array of config/app.php:

  'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],

Finally, add two class aliases to the aliases array of config/app.php:

  'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],
查看更多
登录 后发表回答