Does not enter the driver

1

I have the following route

Route::resource('mail', 'MailController');

Which I call in the following form:

 @extends('layouts.app')
@section('content')
    <div class="content">
        <div class="row">
            @if (Session::has('message'))
                <div class="alert alert-info">{{ Session::get('message') }}</div>
            @endif
            <div class="col-sm-10 ">
                <div class="panel panel-default">
                    <div class="panel-heading">Contáctenos</div>
                    <div class="panel-body">
                        <form class="form-horizontal" method="POST" action="{{route('mail.store')}}">... 
</form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

with its corresponding formrequest:

    <?php

namespace libreir\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MailFormRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nombre' => 'required|string',
            'email' => 'required|email|max:255',
            'texto' => 'string|required'
        ];
    }
}

and I should enter the store method specified in the form's path, but for some anomaly that I do not know, I get the following message:

Any explanation of why and a solution?

    
asked by Maria Rosa Cambero 11.03.2018 в 23:28
source

1 answer

2

This problem occurs because you have not included the CSRF token in the form:

<form class="form-horizontal" method="POST" action="{{route('mail.store')}}">
   @csrf
   ...
</form>

Or in versions prior to Laravel 5.6:

<form class="form-horizontal" method="POST" action="{{route('mail.store')}}">
    {{ csrf_field() }}
    ...
</form>
    
answered by 11.03.2018 / 23:40
source