Error csrf token in laravel

0

I'm getting the error

  

TokenMismatchException   in VerifyCsrfToken.php (line 68)

When I submit on the view information below. Detail is that in all my views I have csrf_token because of the blade template. Anyway, my view is this:

@extends('layouts.app')

@section('content')
<div class="container">

    <h1>Funções do <b>{{$user->name}}</b></h1><br>

    <form action="{{url("/users/{$user->id}/roles/salva")}}" method="POST">
        <div class="form-group">
           <label for="exampleFormControlSelect1" class="col-md-4 control-label">Access Level</label>
           <select class="form-control" id="exampleFormControlSelect1">
               <option name="role_id" value="6">Viewer</option>
               <option name="role_id" value="5">Manager</option>
               <option name="role_id" value="3">Admin</option>
           </select>    
        </div>
        <button type="submit" class="btn btn-success">Adicionar Função</button>
    </form>
    <br>
    <form action="/users" method="get">   
        <button class="btn btn-danger">Voltar</button>
    </form>
</div>
@endsection

I do not know yet if this dropdown will work but it does not matter for now (I think)

@csrf in the form of text in the view

    
asked by anonymous 03.05.2018 / 14:37

1 answer

1

You should put inside your form @csrf .

@extends('layouts.app')

@section('content')
<div class="container">

    <h1>Funções do <b>{{$user->name}}</b></h1><br>

    <form action="{{url("/users/{$user->id}/roles/salva")}}" method="POST">
         @csrf
        <div class="form-group">
           <label for="exampleFormControlSelect1" class="col-md-4 control-label">Access Level</label>
           <select class="form-control" id="exampleFormControlSelect1">
               <option name="role_id" value="6">Viewer</option>
               <option name="role_id" value="5">Manager</option>
               <option name="role_id" value="3">Admin</option>
           </select>    
        </div>
        <button type="submit" class="btn btn-success">Adicionar Função</button>
    </form>
    <br>
    <form action="/users" method="get">   
        <button class="btn btn-danger">Voltar</button>
    </form>
</div>
@endsection

Another way to declare csrf is:

{{ csrf_field() }}

Source: CSRF Protection

    
03.05.2018 / 14:41