I am trying to remove a basic session but it's not removing. Here's the code
welcome.blade.php
@if(Session::has('key'))
{{ Session::get('key')}}
<a href="logout">Sign Out</a>
@else
please signin
@endif
</div>
I don't know how to remove session. Here's the one I used but it's not working route.php
Route::get('/logout', function() {
$vv = Session::forget('key');
if($vv)
{
return "signout";
}
});
You should use this method
You can try with
Session::pull('key');
And if you want to delete all sessions variable you can use
Session::flush();
http://laravel.com/docs/5.0/session#session-usage
Session::forget()
does not return true/false. You can just remove yourif
statement.As a side note, if you're only using the
user
key inSession
for storing the currently logged in user, you can just useAuth::user()
instead.You can use the
Request
parameter, containing the current session. This way you can delete any session value by the key:Or you can delete all values in the session:
Reference: https://laravel.com/docs/5.3/session#using-the-session