【发布时间】:2023-03-16 08:14:01
【问题描述】:
我在从验证 CSRF 令牌中排除路由时遇到问题。
我正在尝试排除我称为 mydomain.com/example 的端点上的所有请求,所以我在 VerifyCsrfToken.php 文件中这样做。
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'example/*',
];
}
但这并不能解决问题。如果我在 app/Http/Kernel.php 文件中执行此操作,则一切正常。
有人知道为什么我不能排除特定路线吗?
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
//\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Barryvdh\Cors\HandleCors::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
【问题讨论】:
标签: laravel