Back

Html, Form class not found in Laravel 5


I can't use Html, Form helper in Laravel 5.

CaporalDead replied 3 years ago

By default in Laravel 5.0, Html and Form are not embedded anymore.

Add the following lines in the require section of composer.json file and run composer update "illuminate/html": "5.*"

Register the service provider in config/app.php by adding the following value into the providers array:

'Illuminate\Html\HtmlServiceProvider'

Register facades by adding these two lines in the aliases array:

'Form'=> 'Illuminate\Html\FormFacade', 'HTML'=> 'Illuminate\Html\HtmlFacade'

mintbridge replied 3 years ago

They are being removed from core in 5 and will need to be added as an optional dependancy in your composer config: https://packagist.org/packages/illuminate/html

yuomtheara replied 3 years ago Solution

Thanks, why remove....

zofe replied 3 years ago

yuomtheara said:

Thanks, why remove....

+1 why?

ludjer replied 3 years ago

The reason why it was removed is because it is not a core component. They want to try and keep it as minimal as possible for basic usage and then it is up to the developer to add the modules that he uses. This speeds up laravel and also allows it to be more modular. The reason why people would not use those service providers is because they are using a Javascript framework and nearly all their interaction with the system is with rests calls.

homoky replied 3 years ago

I have this in my composer:

"require": {
		"laravel/framework": "~5.0",
		"laravel/elixir": "~1.0",
		"illuminate/html": "5.0.*@dev"
	},

But still cannot use Form::whatever.

My view looks like this:

{{ Form::open(array('action' => '[email protected]')) }}

	{{ Form::text('name', @$name) }}

	{{ Form::password('password') }}

	{{ Form::submit('Send') }}

{{ Form::close() }}

And I get:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Call to a member function domain() on a non-object"

Stacktrace:
#1 Symfony\Component\Debug\Exception\FatalErrorException in /Users/petrhomoky/Sites/mailer.dev/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:403
#0 Illuminate\Exception\Handler:handleShutdown in <#unknown>:0

tyrelb replied 3 years ago

Visit here: http://laravel.io/forum/09-01-2014-class-form-not-found And follow usm4n's instructions - just worked for me...

  1. add the following in the require section of the composer.json file and run composer update: "illuminate/html": "4.3.*
  2. add this in providers array of config/app.php file: 'Illuminate\Html\HtmlServiceProvider'
  3. register facades by adding these two lines in the aliases array: 'Form'=> 'Illuminate\Html\FormFacade', 'HTML'=> 'Illuminate\Html\HtmlFacade'
phylaxis replied 2 years ago

ludjer said:

The reason why it was removed is because it is not a core component. They want to try and keep it as minimal as possible for basic usage and then it is up to the developer to add the modules that he uses. This speeds up laravel and also allows it to be more modular. The reason why people would not use those service providers is because they are using a Javascript framework and nearly all their interaction with the system is with rests calls.

So is there a more RESTful way of doing the same thing with Laravel 5?

serrati replied 2 years ago

Try to use {!! !!} instead {{ }}

homoky said:

I have this in my composer:

"require": {
  	"laravel/framework": "~5.0",
  	"laravel/elixir": "~1.0",
  	"illuminate/html": "5.0.*@dev"
  },

But still cannot use Form::whatever.

My view looks like this:

{{ Form::open(array('action' => '[email protected]')) }}

  {{ Form::text('name', @$name) }}

  {{ Form::password('password') }}

  {{ Form::submit('Send') }}

{{ Form::close() }}

And I get:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Call to a member function domain() on a non-object"

Stacktrace:
#1 Symfony\Component\Debug\Exception\FatalErrorException in /Users/petrhomoky/Sites/mailer.dev/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:403
#0 Illuminate\Exception\Handler:handleShutdown in <#unknown>:0

kunfuzi replied 2 years ago

add to your routes.php

Route::post('/users/postL', '[email protected]'); and try {!! Form::open(array('action' => '[email protected]')) !!}

serrati said:

Try to use {!! !!} instead {{ }}

homoky said:

I have this in my composer:

"require": {
 	"laravel/framework": "~5.0",
 	"laravel/elixir": "~1.0",
 	"illuminate/html": "5.0.*@dev"
 },

But still cannot use Form::whatever.

My view looks like this:

{{ Form::open(array('action' => '[email protected]')) }}

 {{ Form::text('name', @$name) }}

 {{ Form::password('password') }}

 {{ Form::submit('Send') }}

{{ Form::close() }}

And I get:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Call to a member function domain() on a non-object"

Stacktrace:
#1 Symfony\Component\Debug\Exception\FatalErrorException in /Users/petrhomoky/Sites/mailer.dev/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:403
#0 Illuminate\Exception\Handler:handleShutdown in <#unknown>:0

AbdullahGhanem replied 2 years ago

hi homoky

you dont add

'providers' => [
          'Illuminate\Html\HtmlServiceProvider',
       ],

and

'aliases' => [
         'Html'
         'Form'
     ]

you can see this tutorial its very good

https://laracasts.com/series/laravel-5-fundamentals/episodes/10

sineld replied 2 years ago

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!

AlessonEvangelista replied 2 years ago

Thank's guys

artmonger replied 2 years ago

I started a new Laravel project and then removed the login features with "php artisan fresh".

I followed the above and updated app.php file and composer.json files.

If I add a form using blade syntax, it works just fine.

However when I want to link the Foundation framework by adding {{ HTML::style('css/foundation.min.css') }}
It is printing the link on my home page:

<link media="all" type="text/css" rel="stylesheet" href="http://localhost:8000/css/foundation.min.css">

I checked the debugging tools in Chrome. Nothing is broken. It's finding the style sheet. Why is it printing the html code to my welcome page?

AndrewBNZ replied 2 years ago

@artmonger

In Laravel 5, the Blade tags changed, {{ }} now outputs escaped text, if you want to output raw text, such as HTML - use {!! !!} instead.

artmonger replied 2 years ago

Ah! That's right.... Thanks, Andrew.

lovePizza replied 2 years ago

Probabily is better the use of Laravel Collective Package: http://laravelcollective.com/

chlebta replied 2 years ago

AndrewBNZ said:

@artmonger

In Laravel 5, the Blade tags changed, {{ }} now outputs escaped text, if you want to output raw text, such as HTML - use {!! !!} instead.

Yeah Thank's so Much :D

randolfarevalo replied 2 years ago

this should be noted in the official laravel 5 documentation :)

euveng replied 2 years ago

This worked for me.

serrati said:

Try to use {!! !!} instead {{ }}

homoky said:

I have this in my composer:

"require": {
 	"laravel/framework": "~5.0",
 	"laravel/elixir": "~1.0",
 	"illuminate/html": "5.0.*@dev"
 },

But still cannot use Form::whatever.

My view looks like this:

{{ Form::open(array('action' => '[email protected]')) }}

 {{ Form::text('name', @$name) }}

 {{ Form::password('password') }}

 {{ Form::submit('Send') }}

{{ Form::close() }}

And I get:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Call to a member function domain() on a non-object"

Stacktrace:
#1 Symfony\Component\Debug\Exception\FatalErrorException in /Users/petrhomoky/Sites/mailer.dev/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:403
#0 Illuminate\Exception\Handler:handleShutdown in <#unknown>:0

Also needed this tweak to make it work.

sineld said:

Just for summarize:

Add to composer.json:

  "illuminate/html": "5.*"

Run:

  composer update

Add to the app.php providers array:

  'Illuminate\Html\HtmlServiceProvider',

Add to the app.php aliases array:

  'Html' 		=> 'Illuminate\Html\HtmlFacade',
  'Form' 		=> 'Illuminate\Html\FormFacade',

Test is out:

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

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

  {!! Form::password('password') !!}

  {!! Form::submit('Send') !!}

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

You are done!

Still catching up with L5!

rjva replied 1 year ago

Hi, on Laravel 5.1, I use: 'providers' - Illuminate\Html\HtmlServiceProvider::class, 'alias' : 'Form' => Illuminate\Html\FormFacade::class, 'Html' => Illuminate\Html\HtmlFacade::class,

Angelin replied 1 year ago

Very important thing that is that the facades are case sensitive, so HTML:: is not the same thing as Html::

ajaysoftdeveloper replied 1 year ago

Sometime you use Form or HTML class in your laravel project you will get error like HTML or FORM class not found. You are getting error because Laravel 5 made changes in their library. You should download HTML and FORM class helper using composer.

Add following code in your composer.json file.

"require": {

"laravel/framework": "5.0.*",

"laravelcollective/html": "~5.0"

},

Open config/app.php and add this line to service providers array:

'Collective\Html\HtmlServiceProvider',

Next, add following line of code to aliases array.

'FORM' => 'Collective\Html\FormFacade',

'HTML' => 'Collective\Html\HtmlFacade',

Reference : http://www.expertphp.in/article/html-form-not-found-in-laravel-5-example

lagbox replied 1 year ago

Don't use illuminate/html use laravelcollective/html. illuminate/html is dead.

If you're using Form or HTML helpers, you will see an error stating class 'Form' not found or class 'Html' not found. The Form and HTML helpers have been deprecated in Laravel 5.0; however, there are community-driven replacements such as those maintained by the Laravel Collective.

For example, you may add "laravelcollective/html": "~5.0" to your composer.json file's require section.

For better security by default, Laravel 5.0 escapes all output from both the {{ }} and {{{ }}} Blade directives. A new {!! !!} directive has been introduced to display raw, unescaped output. The most secure option when upgrading your application is to only use the new {!! !!} directive when you are certain that it is safe to display raw output.

Directly from the Laravel Upgrade Guide for 'to 5.0 from 4.2'

All this stuff is in the upgrade guide.

tahiryasin replied 1 year ago

Solution for Laravel 5.3.x

Package illuminate/html is abandoned, you should avoid using it. Use laravelcollective/html instead.

  • Add below code in "require" section of composer.json:
"laravelcollective/html": "~5.0"
  • Run:
composer update
  • Add to the config/app.php providers array:
'Collective\Html\HtmlServiceProvider',
  • Add to the config/app.php aliases array:
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
  • Test is out:
{!! Form::open([]) !!}

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

{!! Form::password('password') !!}

{!! Form::submit('Send') !!}

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

You are done!

sosmongare replied 8 months ago

this one works fine

fanuch replied 3 months ago

Thanks to @tahiryasin for the well thought out explaination.

Had to change this

'Collective\Html\HtmlServiceProvider',

to this

Collective\Html\HtmlServiceProvider::class,

or else I would get

[Symfony\Component\Debug\Exception\FatalThrowableError]   
Undefined constant 'Collective\Html\HtmlServiceProvider'

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us