Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jasonfrye's avatar

Laravel 5.3 Session Flash Not Working

I have a laravel 5.1 application that I've been porting to 5.3. I started with a brand new installation of 5.3 and moved classes, controllers, views, etc over and tested as I moved. Everything works now except I cannot get session()->flash('success', 'This works!'); to work like they did before. I've spun up a new 5.3 app and the following works there, but returns null in the migrated application.

Route::get('start', function(){
    session()->flash('success', 'This was successful');
    return redirect('/end');
});

Route::get('end', function(){
    dd(session('success'));
});

I've verified that the session.php config file has the same values, minus the cookie name being different. Sessions are being stored everytime I visit the test site and explicit keyed sessions work, like session(['success', 'This was successful']);

Does anyone have any idea what might be causing this problem?

0 likes
6 replies
ejdelmonico's avatar

It is hard to tell without seeing it in context but I do know that if you are using the file driver, you should be able to do what you are doing if your flash is for the very next request. Otherwise, you need to store it differently. Are you using barryvdh debugger? If so, check your session value there. If its there, then maybe use a different way to access it.

ejdelmonico's avatar

I just dumped your code in a testing project and it works for me. I get a redirect to /end with the message from the session.

jasonfrye's avatar

@ejdelmonico it works on my test 5.3 site but not on the one where I'm moving classes into from another fully built laravel application. Quite frustrating as it seems like it'd be a simple thing to get sorted out. I'm at a loss as to where to look any further into it.

jasonfrye's avatar

OK, so I've identified that session flash works outside the web.php routes file, but no routes within that file get the session flash value. There must be a redirect or something happening.

ejdelmonico's avatar
Level 53

So, it must be middleware or controller problem? Something is not quite right in something you brought over. I am getting ready to migrate a 5.1 app to 5.3 or 5.4 soon so I am interested in your issues.

jasonfrye's avatar

It was a middleware problem. I had copied my middleware into both the middleware and middlewaregroups array, so it was getting called twice. Thanks for taking the time to respond.

Please or to participate in this conversation.