{{ csrf_token }} Does not work

Asked

Viewed 122 times

1

I am developing a form but csrf_token does not work:

<form method="POST" action="/storeXML" class="form-inline">
    <div class="container">
        <input type="hidden" value="{{ csrf_token() }}">
        <label class="">Url da integração</label>
        <input type="text" class="form-control" placeholder="Digite a URL do XML">
        <button type="submit" class="btn btn-primary">Enviar</button>
    </div>
</form>

The route is like this:

Route::post('/storeXML', 'IntegrationController@storeXml')->name('store');

And returns the following error:

inserir a descrição da imagem aqui

Any idea how to solve this type of problem?

1 answer

3


The name= country:

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

I think it should be:

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

However in Blade already exists the @csrf, use like this:

<form method="POST" action="/storeXML" class="form-inline">
    <div class="container">

        @csrf

        <label class="">Url da integração</label>
        <input type="text" class="form-control" placeholder="Digite a URL do XML">
        <button type="submit" class="btn btn-primary">Enviar</button>
    </div>
</form>

Before the Laravel 5.6:

Even Laravel 5.5 I think you should use the csrf_field() (do not know if it is supported in new versions to give backward compatibility):

<form method="POST" action="/storeXML" class="form-inline">
    <div class="container">

        {{ csrf_field() }}

        <label class="">Url da integração</label>
        <input type="text" class="form-control" placeholder="Digite a URL do XML">
        <button type="submit" class="btn btn-primary">Enviar</button>
    </div>
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.