Try using the with function on the redirect:
Redirect::to('sandbox')->with('foo', 'bar');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, can someone help me figure out how to flash session data from an exception handler in Laravel 5? Here is where I'm stuck...
This is my exeption handler located in ErrorServiceProvider.php
$handler->error(function(\SampleException $e) use ($log)
{
\Session::flash('foo', 'bar');
return \Redirect::to('sandbox');
});
And here are my routes
// Just dump the session data
$router->get('sandbox', function() {
var_dump (Session::all());
});
$router->get('flash', function() {
\Session::flash('hello', 'world');
return \Redirect::to('sandbox');
});
$router->get('exception', function() {
throw new \SampleException;
});
What has me confused is if I hit the 'flash' route, the session data works. Yet when I dump the session data after hitting the 'exception' route, which has the same code in the handler, the session data is empty. Does anyone know what I'm missing here?
Please or to participate in this conversation.