TokenMismatchException in VerifyCsrfToken.php line 68

TokenMismatchException in VerifyCsrfToken.php line 68

davide_tombaridavide_tombari Posts: 1Questions: 1Answers: 0

hi i'm testing Editor and i have this problem, when i press any button for editing like new, edit or delete i get this error:
"TokenMismatchException in VerifyCsrfToken.php line 68"
i'm using laravel latest version and my php file is this :

<?php

namespace App\Http\Controllers;
use Log;
use Illuminate\Http\Request;
use Datatables;
use DB;
use App\Position;

class PositionController extends Controller
{
//entry point of all request at the moment
public function positionData(Request $request){

 //it is used for loading data 
  if ($request->isMethod('get')) {
      return Datatables::collection(Position::all())->make(true);
  }
  //try to make an empty response
  return Datatables::collection([])->make(true);

}

}

MY ROUTES:
Route::get('position', ['uses'=>'PositionController@index']);
Route::any('position.getpositions', ['as'=>'position.getpositions','uses'=>'PositionController@positionData']);

MY VIEW:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
]) !!};
</script>
<!-- The above 3 meta tags must come first in the head; any other head content must come after these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/buttons.bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/select.bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/editor.bootstrap.min.css') }}" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<table id="dataTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>Position</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Position</th>
</tr>
</tfoot>
</table>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="{!! asset('js/bootstrap.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/jquery.dataTables.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/dataTables.bootstrap.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/dataTables.buttons.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/buttons.bootstrap.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/dataTables.select.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/dataTables.editor.min.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/editor.bootstrap.min.js') !!}"></script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" class="init">
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajax": "{{ route('position.getpositions') }}",
table: "#dataTable",
idSrc: "id", //identificatore del campo usato dai bottoni add delete e edit
fields: [ {
label: "Id:",
name: "id"
}, {
label: "Position:",
name: "position"
}
],

} );

var table = $('#dataTable').DataTable({
"processing": true,
"serverSide": true,
"select": true,
"ajax": "{{ route('position.getpositions') }}",
"columns": [
{data: 'id', name: 'id'},
{data: 'position', name: 'position'}

    ]
});


// Display the buttons
new $.fn.dataTable.Buttons( table, [
    { extend: "create", editor: editor },
    { extend: "edit",   editor: editor },
    { extend: "remove", editor: editor }
] );

table.buttons().container()
    .appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );

} );

    </script>

</body>
</html>

I've tryed everithing but nothing changed, when a make a post request always get the same error at the top.
Help me!!

This discussion has been closed.