DEV Community

Wahid
Wahid

Posted on • Edited on

9

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

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!

Top comments (7)

Collapse
 
awinojanett profile image
Janet Awino

Thank you for this

Collapse
 
palexandrite profile image
Alexander Bulatov

Thank you HUGE much :-)

Collapse
 
manuel_cabreravivas_53df profile image
Manuel Cabrera Vivas

thanks

Collapse
 
marshal_nzenza_cd36b3e859 profile image
Marshal Nzenza

This saved my life, thanks so much.

Collapse
 
sanjudilshan554 profile image
K.A.S DILSHAN

Thank you very much

Collapse
 
dabourz profile image
Stéphane Bourzeix

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
Collapse
 
inwall profile image
Сергей DEV

спасибо тебе

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more