Search code examples
laravel-5laravelcollective

Class 'Form' not found (View: /path/to/laravel/resources/views/posts/create.blade.php)


I am trying to use Forms but keep getting this error:

Class 'Form' not found

and

Class 'Form' not found (View: /path/to/laravel/resources/views/posts/create.blade.php)

my create.blade.php

@section('content')
<div class="row">
  <div class="col-md-8 col-md-offset-2">
    <h1>Новая новость</h1>
    <hr>
      {!! Form::open(['route' => 'posts.store']) !!}
        {!! Form::label('title',"Заголовок:") !!}
        {!! Form::text('title', null, array('class' => 'form-control')) !!}

        {!! Form::label('body', "Текст:") !!}
        {!! Form::textarea('body',null, array('class' => 'form-control')) !!}

        {!! Form::submit('Сохранить', array('class' => 'btn btn-success btn-lg btn-block', 'style' => 'margin-top:10px;')) !!}
      {!! Form::close() !!}
  </div>
</div>
@endsection

I add all needed lines and executed the commands according to the manual at Laravel Collective

Providers:

Collective\Html\HtmlServiceProvider::class,

Alias:

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

Solution

    1. Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/html.

      "require": {
          "laravelcollective/html": "~5.0" 
      }
      
    2. Next, update Composer from the Terminal.

    3. Next, add your new provider to the providers array of config/app.php:

      'providers' => [
          'Collective\Html\HtmlServiceProvider'
      ],
      
    4. Finally, add two class aliases to the aliases array of config/app.php:

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