Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Why is my Laravel 5.7 session not working?

$
0
0

I'm trying to get sessions to work in Laravel 5.7, but I can't seem to get it working; I'm not sure why. I've looked at the official docs, looked at a bunch of SO posts, done Googling for the issue on other sites, and I still can't figure it out.

Basically, I've got a route like the following in web.php:

Route::get('/some_path', 'SomeController@index');

Then, in the index method of SomeController, I have the following:

session(['test', 'Some Value']);session(['test2', 'Some Other Value']);session(['test3', 'Some Third Value']);$value = session('test', 'Backup Value');echo $value;

With that, I'm always getting Backup Value echoed to the screen.

If I go into /storage/framework/sessions, I see a session file that has the following content (which I have anonymized):

a:5:{s:6:"_token";s:40:"token-here";s:9:"_previous";a:1:{s:3:"url";s:26:"http://example.com/some_path";}s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}i:0;s:5:"test3";i:1;s:16:"Some Third Value";}

Basically, it looks like the session is kind of working, but it only seems to store test3. If I comment out the test3 line in the controller, then it only stores test2. And even if I only have the test line in the controller, it still doesn't retrieve the value.

I also tried switching the session to a DB session with the proper session migrate file a la https://laravel.com/docs/5.7/session, but it's still not working.

Basically, I have no clue what's up. I can say that I'm not using the native Laravel auth, so I'm not sure if that matters, but I feel like it shouldn't. Also, I tried restarting my localhost, but that didn't make a difference and running both of the following commands, neither of which seem to change anything:

php artisan config:clearphp artisan route:clear

Lastly, I tried adding use Session at the top of the controller, but that doesn't seem to matter either.

Basically, I don't know what to do. What could possibly be causing this? Thank you.


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>