Forms & HTML for Laravel 5.2.X

If you are working on newest Laravel Framework, you will find why the Forms & Html disappeared from Laravel 5.2.x. Especially for those developers who was working on Laravel 4.x

That’s not surprise, actually since Laravel 5.1.x, Form &  Html has been removed from Laravel core framework. I remember many developers asked how to add it back. So you can add it back by below steps:

Just for summarize:

Add to composer.json:

  “illuminate/html”: “5.*”

Run:

  composer update

Add to the app.php providers array:

  Illuminate\Html\HtmlServiceProvider::class,

Add to the app.php aliases array:

  ‘Html’      => Illuminate\Html\HtmlFacade::class,
   ‘Form’      => Illuminate\Html\FormFacade::class,

Test is out:

  {!! Form::open([]) !!}

   {!! Form::text(‘name’, @$name) !!}

   {!! Form::password(‘password’) !!}

   {!! Form::submit(‘Send’) !!}

   {!! Form::close() !!}

You are done!

But if you are using Laravel 5.2.x, you will find you got fatal error: Call to undefined method bindShared(). That’s correct, because the “bindShared() has been replaced by “singleton()”.

Is that okay to solve the issue just by replacing method name?

/**
* Register the HTML builder instance.
*
* @return void
*/
protected function registerHtmlBuilder()
{
$this->app->singleton(‘html’, function ($app) {
return new HtmlBuilder($app[‘url’], $app[‘view’]);
});
}

STOP, do not try that way. Here is right place to go.

https://laravelcollective.com/docs/5.2/html

That’s the official community takeover of illuminate/html and should be a drop-in replacement.

Advertisements

About qianggan

Sr. Software Engineer
This entry was posted in Laravel. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s