I've got a Laravel 5.2 project that I'm using as a mock API for a javascript client I'm building out. The mock API functionality will be replaced with a different Laravel project later. For now, I just need to be able to submit API calls and get expected responses.
In my mock API I'm storing the authentication status in the session.
The problem I'm running into is that the values I put into the session are not persisting between http calls.
This seemed similar to a different stackoverflow post I found, but the thing is I'm already using the web
middleware for my API group.
I thought it may be a permissions on my storage folder (I'm using the default file
session driver), vagrant is the owner and has write access:
Plus if it was a permissions issue I would think it would generate a runtime error.
Is there something else I'm missing?
Here's the contents of Config::get('session')
:
And yep, the StartSession
class is included in the web
middleware group:
Here's a shot of the browser session cookie vs the session file being created on the web server:
Here's the content of the request:
Laravel ships with several great drivers out of the box: file - sessions will be stored in storage/framework/sessions . cookie - sessions will be stored in secure, encrypted cookies. database - sessions will be stored in a database used by your application.
How long does laravel session last? You need to understand what happened: You've set the lifetime of the sessions to 120 minutes, which means after 120 minutes the session is flushed. The remember_me feature is using cookies.
The correct syntax for this is: Session::set('variableName', $value); For Laravel 5.4 and later, the correct method to use is put : Session::put('variableName', $value);
I had the same issue and was able to get it to work by replacing
Route::group(['middleware' => ['web']], function () {
...
});
with
Route::group(['middlewareGroups' => ['web']], function () {
...
});
No idea why this works though when all the documentation suggests that we use ['middleware' => ['web']]
One thing that did the trick for me was to make sure that domain in config/session.php is set to null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With