mrWodoo's avatar

[LUMEN] Csrf middleware problem

So I have a problem, because I want to secure my POST form against CSRF, but I can't do that, I can't fetch the csrf token (via csrf_token()), no errors, returns empty string, what's the problem? (Middlewares enabled etc., googled a lot)

0 likes
3 replies
bestmomo's avatar

You can use session()->getToken() in your views

mrWodoo's avatar

Doesn't change anything. I just can't get CSRF token, not in view (csrf_token() function) or in controller (csrf_token()), there are no errors etc. but If I submit my form I get an error about csrf token mismatch

tinymondo's avatar

Just encountered the same problem.

In your bootstrap/app.php you have have to uncomment at least the lines with StartSession and VerifyCsrfToken to get the csrf_token function to spit out a token.

$app->middleware([
    // Illuminate\Cookie\Middleware\EncryptCookies::class,
    // Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    // Illuminate\Session\Middleware\StartSession::class,
    // Illuminate\View\Middleware\ShareErrorsFromSession::class,
    // Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class,
]);

Please or to participate in this conversation.