HartleySan
HartleySan

Reputation: 7810

Why am I getting a "Class 'App\Providers\Form' not found" error in Laravel 5.5.43?

I did a Laravel 5.5.43 installation this morning with the following Composer command:

composer create-project laravel/laravel project-name

I then ran the following command in the project folder to install Laravel Collective:

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

I then added the following under providers in config/app.php:

Collective\Html\HtmlServiceProvider::class,

And I added the following under aliases in config/app.php:

'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

After that, I wanted to create custom form components, so I ran the following Artisan command:

php artisan make:provider FormServiceProvider

And in that new provider file, I added the following line to the boot method:

Form::component('customText', 'components.form.text', ['name', 'value' => null, 'attributes' => []]);

Lastly, I added the following to providers in config/app.php:

App\Providers\FormServiceProvider::class,

When I do that though and refresh the Laravel instance from the browser, I get the following error:

Class 'App\Providers\Form' not found

However, if I add the following at the top of the FormServiceProvider.php file, then it works:

use Collective\Html\FormFacade AS Form;

I understand the concept of namespaces and why that makes the Form::component method in the boot method in the file properly work, but what I don't get is why I need to add that use line to the file at all.

Isn't the 'Form' => Collective\Html\FormFacade::class, line in the aliases array in the app.php file supposed to do that for me so I don't need to add the use line to the FormServiceProvider.php at all? What am I missing / doing wrong / not understanding?

Thank you.

Upvotes: 0

Views: 1508

Answers (2)

HartleySan
HartleySan

Reputation: 7810

I probably should just delete this question, but the simple answer was to add the following at the top of the FormServiceProvider.php file:

use Form;

Thanks.

Upvotes: 2

user10186369
user10186369

Reputation:

Run below command:

php artisan config:cache
php artisan cache:clear

Upvotes: 1

Related Questions