Laravel 7 Class 'Form' not found

In Laravel 5 earlier versions, Laravel Form builder was already installed, but on new Laravel versions it is not preinstalled. SO whenever you add Form builder in blade file, you will get error 'Class Form not found'.

To use Laravel Form builder first you have to install laravelcollective/html to project through Composer.

Put the below lines in composer.json

"require": {
        "laravelcollective/html": "^6.0"
 },

and Run command

composer update

or directly install using command

composer require laravelcollective/html

This will install Laravel Form builder package to use in blade file.

Now open config/app.php file and put the below line in 'providers' array.

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

In the same file add these two class aliases in aliases array.

'aliases' => [
    // ...
    'Form' => 'Collective\Html\FormFacade',
    'Html' => 'Collective\Html\HtmlFacade',
    // ...
],

Now, you can use of laravel form builder in your blade file.

{!! Form::open(['url' => 'foo/bar']) !!}
	// ...
{!! Form::close() !!}

Have a happy coding!

Tags: