In my Laravel 5.2 application I have a very peculiar error. My Session variables are storing and working perfectly, but my Session Flash Data does not seem to work no matter what I try. I've tested this on both my local development machine and live production server, and Session Flash Data is not working in both places. I have other Laravel 5.1 and 5.2 projects on both machines and never encountered anything like this. Here's my code:
Route::group(['middleware' => ['web']], function () {
// If I go here, it redirects to 'session/result', but on that page it always
// outputs: "No value in Session flash_message found"
// So, it's not detecting the flash_message on the redirected page! :(
Route::get('session/test-flash', function() {
Session::flash('flash_message', 'This is my flash message!');
return redirect('session/result');
});
// I made this just to test that Sessions are indeed working PROPERLY
// Which is so strange that Sessions are working fine, but
// Flash Data is not?
Route::get('session/test-set', function() {
Session::set('flash_message', 'This is my flash message!');
return redirect('session/result');
});
// This is the page that it redirects to, which checks to see if a
// session variable is present. In this example,
// Session::has('flash_message') is failing when redirecting from
// after setting a flash_message. Please help me figure out why!
Route::get('session/result', function() {
if(Session::has('flash_message'))
echo 'Session "flash_message" variable is: ' . Session::get('flash_message');
else
echo 'No value in Session flash_message found';
});
// I'm just using this to reset Session data to help test
Route::get('session/flush', function() {
\Session::flush();
die('Session flushed.');
});
});
If I go to http://myapp/session/test-flash, it redirects to 'session/result', and it always fails to show the flash_message - it says "No value in Session flash_message found" no matter what I try! However, if I go to http://myapp/session/test-set, it does successfully set my Session variable after it redirects to 'session/result'. So, Sessions ARE working properly, just not Flash Data. :(
I'm not sure what to do here! I'm ripping my hair out. I've even gone so far as to do things like chmod -R 777 storage, php artisan key:generate, and other things that I don't think would work but out of desperation would hope it fixes it. I've even given the code to a Laravel friend through IRC (shoutouts to lagbox) and it's working fine on his machine, just not mine! :(
Please if you can provide any insight on how to solve this problem so that my Session Flash Data will work properly, or help me figure out what I might be doing wrong, it would be greatly appreciated.