Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove sessions in Laravel 5

Tags:

php

laravel-5

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";
   }
});
like image 367
rockie Avatar asked Apr 05 '15 21:04

rockie


People also ask

How do I delete a specific session in laravel?

In this article, we will see how to solve Forget Or Remove A Session In Laravel with examples. //remove single session Session::forget('Sessionkey'); //remove multiple sessions Session::forget(['sessionKey1', 'sessionkey2']); //remove all sessions Session::flush();

How do I delete a session?

In order to kill the session altogether, the session ID must also be unset. If a cookie is used to propagate the session ID (default behavior), then the session cookie must be deleted.

What is session pull in laravel?

The pull method will retrieve and delete an item from the session in a single statement: $value = $request->session()->pull('key', 'default');


2 Answers

You should use this method

 Route::get('/logout', function() {
 Session::forget('key');
  if(!Session::has('key'))
   {
      return "signout";
   }
 });
like image 112
Imtiaz Pabel Avatar answered Sep 25 '22 18:09

Imtiaz Pabel


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

like image 37
Clément Rigo Avatar answered Sep 22 '22 18:09

Clément Rigo