Laravel5:compiled.php第3123行中的TokenMismatchException: [英] Laravel5: TokenMismatchException in compiled.php line 3123:

查看:86
本文介绍了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'
 ];

这篇关于Laravel5:compiled.php第3123行中的TokenMismatchException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆