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

2019-08-02 19:55发布

问题:

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') }}">

回答1:

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.



回答2:

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,
    // ...
  ],


标签: forms laravel