Laravel:以编程方式从VerifyCsrfToken中间件中排除路径

时间:2018-04-16 11:02:27

标签: laravel csrf-protection

我想知道是否可以通过编程方式将路由添加到 VerifyCsrfToken 类中的 $ except 变量。

class VerifyCsrfToken extends BaseVerifier
    {
        /**
         * The URIs that should be excluded from CSRF verification.
         *
         * @var array
         */
        protected $except = [
            //
        ];
    }

我正在开发一个从支付网关收听webhooks / postback的软件包。如果在安装软件包时将自定义路由添加到 $ except 变量,那就更好了。

由于

1 个答案:

答案 0 :(得分:0)

我决定将自定义路线添加到api.php

file_put_contents(
 base_path('routes/api.php'),
 file_get_contents(__DIR__.'/stubs/make/routes.stub'),
 FILE_APPEND
);

VerifyCsrfToken中间件不拦截 api.php中的路由