You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This no longer works in the "new" application structure introduced in Laravel 11. New Laravel projects no longer include this middleware by default. Extending the VerifyCsrfToken (or ValidateCsrfToken, it was renamed) middleware as you used to do is no longer automatically picked up by Laravel. The "base" implementation (\Illuminate\Foundation\Http\Middleware\ValidateCsrfToken) is always used.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In previous Laravel versions (
<11.x
), one could easily disable theXSRF-TOKEN
HTTP cookie by setting the$addHttpCookie
class property of https://github.com/laravel/laravel/blob/10.x/app/Http/Middleware/VerifyCsrfToken.php tofalse
.This no longer works in the "new" application structure introduced in Laravel 11. New Laravel projects no longer include this middleware by default. Extending the
VerifyCsrfToken
(orValidateCsrfToken
, it was renamed) middleware as you used to do is no longer automatically picked up by Laravel. The "base" implementation (\Illuminate\Foundation\Http\Middleware\ValidateCsrfToken
) is always used.The only workaround I've found for this, is to manually replace this middleware with my own implementation like so:
This is quite verbose and cumbersome to implement.
Proposal
Ideally the Laravel framework would provide developers some way to express the desire to disable this cookie that is both expressive and concise.
One could expand the method signature of
public function validateCsrfTokens(array $except = [])
to include a secondary, optional argument:Or, an additional method is added to
Middleware
:These are just two examples on how this could be changed/improved.
Beta Was this translation helpful? Give feedback.
All reactions