I am setting few session variables in my search controller as below:
// Add the search form values to session too
session()->put('search-keyword', $keyword);
session()->put('search-geolocation', $geoLocation);
Later,
return view('search.index', compact('profiles'));
In my search blade template, have this line:
<div style="background-image:url( '{{ $profile['_source']['picture'] }}' )"></div>
I am using 'file' session driver and the above works very well until $profile['_source']['picture'] is null. When it is null, for some reason session variable search-geolocation is never set! As checked in the session file at storage/framework/sessions: ...."search-geolocation";N;s:9....
If I change the <div> above to <img>, everything again works beautifully, regardless of whether $profile['_source']['picture'] is null or not null:
<img src="{{ $profile['_source']['picture'] }}" alt="">
This same problem never happens with the session variable search-keyword, whether $profile['_source']['picture'] is null or not null; search-keyword appears as it should in the session file.
Right after setting the session in the controller, I get correct value when I echo:
echo session()->get('search-geolocation');
Also, this problem goes away when I debug the code (XDebug) and all the values are stored correctly in the session file as expected. So, debug is not of much help.
I have already worked around this problem but I am not confident about session anymore. Therefore, want to understand what's going on here. Have tried changing the session driver without any difference.