I am not sure why it happens and it's driving me nuts, I have the following code:
public function some_method(Request $request)
{
if(session()->missing('key1')) {
session(['key1' => 'some_value1']);
dd("key1 is missing");
}
if(session()->missing('key2')) {
session(['key2' => 'some_value2']);
dd("key2 is missing");
}
}
So after the first refresh, I get "key1 is missing" because it was not set at the first request. But then it keeps showing me "key2 is missing". It enters the if condition but doesn't create the key2 as it did with key1.
Update: If I set key2 outside the if, it works
// some controller
public function some_method(Request $request)
{
// setting key2 outside the if
session(['key2' => 'some_value2']);
if(session()->missing('key1')) {
session(['key1' => 'some_value1']);
dd("key1 is missing");
}
if(session()->missing('key2')) {
session(['key2' => 'some_value2']);
dd("key2 is missing");
}
}
@ligonsker Don’t know, but my intuition is that this isn’t your actual code, and that you’ve probably changed stuff under the hood since you spent the last few weeks creating multiple threads asking how to change Laravel’s session handling to do weird time out stuff.
@martinbean No haha this is unrelated to the other session topics, which I ended up using Cache.
This time, it's a new controller, the only difference in the actual code is the keys. It really looks like that. I just also tried to check, if I set the key outside the condition, it works:
// some controller
public function some_method(Request $request)
{
// setting key2 outside the if
session(['key2' => 'some_value2']);
if(session()->missing('key1')) {
session(['key1' => 'some_value1']);
dd("key1 is missing");
}
if(session()->missing('key2')) {
session(['key2' => 'some_value2']);
dd("key2 is missing");
}
}
So I am not sure why it won't set the key from inside the if