How to Fix Session store not set on request Laravel 11?
Wahid

Wahid @abdulwahidkahar

About: Writing about the mistakes I made in software development and the solutions I found to overcome those challenges.

Location:
Indonesia
Joined:
Nov 12, 2023

How to Fix Session store not set on request Laravel 11?

Publish Date: Aug 26 '24
13 8

Add the following code in the bootstrap/app.php file:

use Illuminate\Session\Middleware\StartSession;
$middleware->append(StartSession::class);
Enter fullscreen mode Exit fullscreen mode

Image description

This is because the way we register custom middleware has changed slightly compared to Laravel 10 and earlier versions.

Hope this helps, thank you!

Comments 8 total

  • Marshal Nzenza
    Marshal NzenzaOct 8, 2024

    This saved my life, thanks so much.

  • Manuel Cabrera Vivas
    Manuel Cabrera VivasOct 14, 2024

    thanks

  • Janet Awino
    Janet AwinoOct 14, 2024

    Thank you for this

  • K.A.S DILSHAN
    K.A.S DILSHANOct 20, 2024

    Thank you very much

  • Alexander Bulatov
    Alexander BulatovDec 27, 2024

    Thank you HUGE much :-)

  • Stéphane Bourzeix
    Stéphane BourzeixFeb 5, 2025

    That is wrong, by doing this you restart the session on each request, so for exemple flash message won't work anymore.

    Correct method is to append your middleware to the Web Middleware :

    ->withMiddleware(function (Middleware $middleware) {
            //Lang
            $middleware->web(append: [
                Language::class,
            ]);
        })
    
    Enter fullscreen mode Exit fullscreen mode
  • Salifou Moussa Abdoul Hack
    Salifou Moussa Abdoul HackMar 20, 2025

    thank u very much

Add comment