php – Laravel 7 "Class 'Form' not found"-ThrowExceptions

Exception or error:

I went to work Laravel!
when I typed in my code

{{ Form::token()   }}

I got the message “Class ‘Form’ not found”!
I went to google to investigate this error but the results are all for laravel versions 4,5,6 nowhere for version 7
And that confuses me a bit I can’t orient myself!
Please Help me!

create.blade.php


@section ('content')
    <form action="{{ URL::route('account-create-post') }}" method="post">
            <input type="submit" value="Create Account">
            {{ Form::token() }}
    </form>
@stop 

Web.php

Route::group(array('brefore' => 'guest'), function() {

    Route::group(array('brefore' => 'csrf'), function(){

        Route::post('/account/create',array(
            'as' => 'account-create-post',
            'uses' => 'AccountController@postcreate'
        ));

    });
}
How to solve:

One of the reason that you may get the error Class ‘Form’ not found is that you have not been registered the form on your config/app.php. You should register it if you have not done it yet.
here is an example:

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

If you have not installed yet install it and register it.
you can add csrf token with other methods if you want.
You can use blade for this like this

 <form action="{{ URL::route('account-create-post') }}" method="post">
            <input type="submit" value="Create Account">
            @csrf
    </form>

If you need just token, you can get it with csrf_token() like this:

<input type="hidden" name="_token" value="{{csrf_token()}}">

Answer:

I got the message “Class ‘Form’ not found”! I went to google to investigate this error but the results are all for laravel versions 4,5,6 nowhere for version 7 And that confuses me a bit I can’t orient myself!

No. You can only use the Form class maximum Laravel version 4.

The Form and HTML helpers have been deprecated since Laravel 5. However, there are community-driven replacements such as those maintained by the Laravel Collective.

Anytime you define an HTML form in your application, you should include a hidden CSRF token field in the form so that the CSRF protection middleware can validate the request. You may use the @csrf Blade directive to generate the token field:

<form action="{{ route('account-create-post') }}" method="POST">
    @csrf

    ...
</form>

Leave a Reply

Your email address will not be published. Required fields are marked *