I am using Laravel 5.1. I am following a tutorial that is made in Laravel 5. I am working with form but it's not working properly.
I'm facing this error:
FatalErrorException in 44a7f556a7d1beef3d09ba2ba2e3c7f0 line 7: Class 'form' not found
How do I fix this?
Update composer.json (require part)
"laravelcollective/html": "5.1.*"
Run command , to update
composer update
Add to providers array
Collective\Html\HtmlServiceProvider::class,
Add to aliases array
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
Related
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.
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.
Run below command:
php artisan config:cache
php artisan cache:clear
I'm having trouble with importing a css style sheet located in public/css in a blade file located in resources/views/includes.
The code I used in the blade file is
{{ HTML::style('css/layout.css') }}
which didn't work. I also tried
{{ HTML::style('css/layout.css', array('media' => 'print')) }}
The error I get is Class 'HTML' not found
I followed the steps in this question, so
I added "laravelcollective/html": "5.4.16" in composer.json
run composer update
added in config/app.php
'providers' => [
Collective\Html\HtmlServiceProvider::class,
]
and
'aliases' => [
'Form' => Collective\Html\FormFacade::class,
'HTML' => Collective\Html\HtmlFacade::class,
]
Now the error I get is
Class 'Collective\Html\HtmlServiceProvider' not found
And I don't understand why, as I added it to app.php. Indeed, when I go to app.php and the line where I added Collective.., the "Html" is colored in red and when I hover over it it says
Undefined namespace Html
What should I do about it? All this laravel thing is getting confusing to me.
Apart from the fact that I don't know what to do with,
{{HTML::linkAction('MemberController#show', 'view', array($value->id))}}
i found nothing online regarding the arguments of "linkAction"
1:Remove "laravelcollective/html": "5.4.16" in composer.json and clean other config for this package in config/app.php.
2:Run composer update
3:Run composer require laravelcollective/html
4:Add 'Collective\Html\HtmlServiceProvider::class', in config/app.php (providers)
5:Add 'Form' => Collective\Html\FormFacade::class, and 'Html' => Collective\Html\HtmlFacade::class, in config/app.php (aliases)
6:In controller try use Html; and use Form;
If you get any other error please share composer.json and config/app.php.
Im am a beginner in Laravel, running version 5.2.16. I have been using PHP for quite some time but i have to get used to the MVC structure.
I have successfully added the optional dependancy for Html and Form, and they work.
I am trying to add a view where a client can register to my site, this view includes various forms. Now, when i try to route the view (register.blade.php) to the controller (RegisterController.php) I keep getting errors.
I suspect that I use the namespaces wrong, or that i doesn't "Use" the right things.
routes.php:
Route::get('register', 'RegisterController#showRegister');
RegisterController.php:
<?php
namespace App\Http\Controllers;
class RegisterController extends Controller {
public function showRegister()
{
return view('register');
}
}
In my config/app.php file i have added: (Should this be Illuminate instead of Collective?)
'providers' => [
...
Collective\Html\HtmlServiceProvider::class,
'aliases' => [
...
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
After i have made these changes i run:
$ composer update
$ php artisan cache:clear
$ php artisan route:clear
However, this still gives med the error:
Fatal error: Class 'Form' not found (View: /Applications/MAMP/htdocs/myProject/resources/views/register.blade.php)
Any ideas?
My files are setup as this
Within Laravel versions < 5.0 FormFacade is already within your app/config/app.php but in Laravel versions > 5 you need to manually place the third party Facades like as
Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/html.
"require": {
"laravelcollective/html": "~5.0"
}
Next, update Composer from the Terminal:
composer update
Next, add your new provider to the providers array of config/app.php:
'providers' => [
// ...
'Collective\Html\HtmlServiceProvider',
// ...
],
Finally, add two class aliases to the aliases array of config/app.php:
'aliases' => [
// ...
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
// ...
],
Docs
I understand that there are several similar questions here but none of them fixed my problem.
I'm trying to add the HtmlServiceProvider with Laravel 5 on Ubuntu 14.04. I keep getting the following error:
dl#dl-VirtualBox:~/l5todo$ composer update
> php artisan clear-compiled
PHP Fatal error: Class 'Illuminate\Html\HtmlServiceProvider' not found in /home/dl/l5todo/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Illuminate\Html\HtmlServiceProvider' not found
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Fatal error: Class 'Illuminate\Html\HtmlServiceProvider' not found i
n /home/dl/l5todo/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository
.php on line 146
My vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository
.php looks like:
/**
* Create a new provider instance.
*
* #param string $provider
* #return \Illuminate\Support\ServiceProvider
*/
public function createProvider($provider)
{
return new $provider($this->app);//line 146
}
My /.../config/app.php looks like:
'providers' => [
Illuminate\Html\HtmlServiceProvider::class, //newly added
......
],
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
......
'Form' => Illuminate\Html\FormFacade::class,
'Html' => Illuminate\Html\HtmlFacade::class,
],
In my compose.Jason
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"Illuminate/Html": "~5.0"
},
Any help would be really appreciated.
Sorry again if this question seems duplicated to you.
composer update works if I remove provider and aliases I added. But after I add them back in, same error appears.
Step 1
In composer.json under require, add:
"laravelcollective/html": "5.1.*",
Step 2
run composer update in your terminal
Step 3
Add the following in config/app.php under providers:
Collective\Html\HtmlServiceProvider::class,
Step 4
Add the following in config/app.php under aliases:
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
Step 1
composer.json
"illuminate/html": "~5.0"
Step 2
process dump-autoload
composer.phar dump-autoload
Step 3 app.php
Illuminate\Html\HtmlServiceProvider::class,
and
'Form' => Illuminate\Html\FormFacade::class,
Step 4 flush caching (if needed)
composer.phar dump-autoload
php artisan config:clear
php artisan clear-compiled
Ok, this is driving me mad. I'm trying to include forms functionalities with FormFacade with Laravel 5, but I keep getting this error:
Class 'Illuminate\Support\Facades\FormFacade' not found
I'll write down what I have done:
After laravel 5 installation, I added FormFacade to laravel.
Updated the app.php file with the following lines:
Providers:
'Illuminate\Html\HtmlServiceProvider',
Aliases:
'Form' => 'Illuminate\Support\Facades\FormFacade',
'Html' => 'Illuminate\Support\Facades\HtmlFacade',
Then, I checked my composer.json file:
"require": {
"laravel/framework": "5.0.*",
"illuminate/html": "~5.0"
},
Did a composer update
Checked if I actually downloaded the files
All of this is done, but still I cannot find whats going wrong. I searched for help but nothing seems to work.
Search effort:
Laracasts tutorial
Class 'Illuminate\Html\HtmlServiceProvider' not found Laravel 5
http://tutsnare.com/class-form-or-html-not-found-in-laravel-5/
Still no luck. Have I missed something?
PS: I'm running on windows.
Those aliases are wrong. You should use the facades from Illuminate\Html:
'Html' => 'Illuminate\Html\HtmlFacade',
'Form' => 'Illuminate\Html\FormFacade',