THE SITUATION:
Sorry in advance if it has already been asked. But no matter what I can never make it works.
I am using Laravel 5 as API.
I have a simple function to edit a task.
I am testing it through my web app or through Postman.
I am always getting this error:
TokenMismatchException in compiled.php line 3123:
THE CODE:
The function:
public function updateTask(Request $request) { $id = $request->input('id'); $task = Task::find($id); $task->name = $request->input('name'); $task->type = $request->input('type'); $task->save(); return $task; }
The route:
Route::group(['middleware' => ['web']], function () { Route::post('update', 'TaskController@updateTask'); });
THE QUESTION:
Why I am getting that error?
Advertisement
Answer
I solved it by inserting the route name as an item in the array $except in the file:
app/http/Middleware/VerifyCsrfToken.php
Like this:
/** * The URIs that should be excluded from CSRF verification. * * @var array */ protected $except = [ 'update' ];