The session()->forget('user_role')
is performing well. However, You are still able to view/print because browser has cached that page and instead of making a network call, request just heats the cache.
To identify and disable cached for a while, Open up the dev tools and disable cache while dev tool is open and refresh the page. After that, you'll no longer be able to see that data stored in the session key. For your reference, The page you are seeing is browser cached one.
This is the temporary solution if you want to check the value being washed or not. However, if you don't want your user to have this behavior, You can try given solutions.
For the browser-based cache control, you should try setting the Cache-Control
, Pragma
and Expires
header with your page response as given,
$contents = View::make('viewname');
return response($contents)-> withHeaders([
'Cache-Control' => 'no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => 0
]);
this will allow you to control the page being cached in browser. Setting the Expires
to 0 means the page never gonna be cached. You can refer the Official MDN Docs here.
You should also try disabling the Laravel blade view cache if the problem still persists or other solution doesn't give satisfactory outcome.