Hello
Currently I was trying to share a variable which uses Session ID like so.
$currentSessionID = session()->getId();
$inCartDetails = Cart::where('session_id', $currentSessionID)->get();
View::share('inCartDetails', $inCartDetails);
I had placed this in the boot of AppServiceProvider but it did not work because "session data is not accessible in the app boot process, You should use middleware like Taylor Otwell said in Add event for session started conversation".
I followed as it says and created a middleware called CommonData
public function handle($request, Closure $next)
{
$currentSessionID = session()->getId();
$inCartDetails = Cart::where('session_id', $currentSessionID)->get();
View::share('inCartDetails', $inCartDetails);
// return $next($request);
}
How would I use this variable from the middeware in a header that is globally on all my views? The header in itself doesn't have a controller since it's included in the master blade. Any ideas?