Laravel 5 session not persisting after user is logged in
Solution 1:
I faced similar issue, I simply called:
Session::save();
after any add/update/delete to Session storage. So it looked like:
$id = Input::get('id');
Session::forget('cart.' .$id);
Session::save();
Solution 2:
I had the same issue. Once I removed the various combinations of dd() and print_r() I was using to dump responses for testing purposes and allowed the method to complete and fully render the view, the issue went away and sessions persisted.
Solution 3:
I solved changing
'cookie' => 'laravel_session',
to
'cookie' => 'myapp_session',
according to laravel the name of the cookie affects every driver
Solution 4:
I'm not familiar with Laravel, but on CodeIgniter I save user session in CI's Session Class and Laravel has one too.
I suggest to use the build-in session which is more persistent than default $_SESSION - probably it saves user data in database and on each page refresh/change the session is populated again from DB.
When user authenticates, just save its session data like this:
Session::put('userData', 'value');
...where value could be just a boolean value or an entire object that holds user specific data.
On each page load, get user data from session:
$user = Session::get('userData');
if($user->id) echo 'user is logged-in'; //or if($user) - depends on what you store in 'userData' key
else echo 'guest only privilegies';
EDIT:
I see that you use the Auth Class. My answer is mostly for manual login of the user and it works.
I think that the Auth Class should be doing this by default, but probably you're missing some configuration or there's a bug.
Here's a possible solution (Laravel 4, but it worths a try): http://laravel.io/forum/11-11-2014-authcheck-always-returning-false
Update:
As of this you should try to change the driver value from
'driver' => env('SESSION_DRIVER', 'file')
to
'driver' => 'file'
...also on Laravel's docs you can see that the driver has to be defined like that.
Solution 5:
First, make sure you don't have some sort of a before filter, middleware, or route group that is causing them to be logged out. At least temporarily, search for any Auth::logout() and comment it out. I have seen this be the problem more than once.
Second, you look like you're doing this call correctly. The third parameter is $login : bool and it defaults to true. This is not your problem, but please change your TRUE and FALSE to true and false to meet with PSR-1/2 standards.
I would have advised that you try another driver, but you have done that and have the same result. This leads me to think that you have some sort of earlier code that is misdirecting to a logout().