Laravel5:compiled.php第3123行中的TokenMismatchException:

问题描述:

情况:

对不起,如果已经被询问过.但是,无论我做什么都无法使它生效.

Sorry in advance if it has already been asked. But no matter what I can never make it works.

我正在使用Laravel 5作为API.

I am using Laravel 5 as API.

我有一个简单的功能来编辑任务.

I have a simple function to edit a task.

我正在通过我的Web应用或邮递员对其进行测试.

I am testing it through my web app or through Postman.

我总是收到此错误:

TokenMismatchException in compiled.php line 3123:

代码:

功能:

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;
}

路线:

Route::group(['middleware' => ['web']], function () {

    Route::post('update', 'TaskController@updateTask');
});

问题:

为什么我会收到该错误?

Why I am getting that error?

我通过在文件中的$ except数组中将路由名称作为一项插入到项目中来解决了该问题:

I solved it by inserting the route name as an item in the array $except in the file:

app/http/Middleware/VerifyCsrfToken.php

赞:

/**
 * The URIs that should be excluded from CSRF verification.
 *
 * @var array
 */
 protected $except = [

     'update'
 ];