Just a simple function in native php
protected function some_function(){
session_start();
if(!isset($_SESSION['a']))
{
$_SESSION['a'] = 'some value';
return true;
} else {
return $_SESSION['a'];
}
}
on the 1st run, it will return bool(true) and then "some value"
as expected.
Applying the same to laravel session,
protected function some_function(){
$a = Session::get('abc');
if(is_null($a)){
Session::put('abc', 'some value');
//return Session::get('abc');
return true;
} else {
return $a;
}
}
By logic, on the 1st run, $a will be null
. and then puts "some value"
in abc
key and returns bool(true) as expected.
However on consequent access, the Session::get('abc')
returns null every time. so every attempt returns bool(true).
I assumed may be session wasn't writing properly so i checked with getting the key value right after setting it.
by commenting out the line in the above code, it returns whatever value i put in Session::put('abc')
. So there is no error in writing the data.
Problem here is trying to retrieve the value always returns null
though i have set after the 1st request.
Am i missing something here?
EDIT
Using database as the driver, The sessions does not get save in database. No error is outputted. Database implementation has been correct with sessions table schema as described in docs.
file
driver as of now. application key is set. - itachidd()
, it won't get save. If you indeed need to save, you need to callSession::save()
manuely after putting the value but before exiting. Let me know if it was hard to follow. - itachiSession::get()
method has replaced other put methods that were acting up. - mattl