【问题标题】:How to disable csrf protection for a route with parameter?如何禁用带参数的路由的 csrf 保护?
【发布时间】:2017-01-20 15:17:38
【问题描述】:

有这样一条路线:

Route::post('user/{id}/update','UserController@update');

我想为其禁用 csrf 保护,但我不知道如何将其 uri 添加到 except 数组中。

【问题讨论】:

    标签: laravel laravel-5.3


    【解决方案1】:

    您可以在VerifyCsrfToken 文件App/Http/Middleware 中添加给定的代码

    protected $except = [
        'user/*',
    ];
    

    或者你可以在路由文件中禁用它

    Route::post('user/{id}/update', [
       'uses' => 'UserController@update',
       'nocsrf' => true,
    ]);
    

    【讨论】:

    • 您好,我没有看到文档中的第二个。你能给我一个关于第二种方法的链接吗?
    猜你喜欢
    • 2023-03-10
    • 2017-03-19
    • 2021-03-02
    • 2015-03-11
    • 2019-11-12
    • 2015-01-17
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    相关资源
    最近更新 更多