Reputation: 5030
I have a method in a controller that needs to handle the session. That method is called by a get method that doesn't require any user input, so I would like to do it without Request
class.
Currently, I am able to set the session, but I cannot find a way to delete it. It looks something like this:
if ($boolean_storing_condition_value)
session(['some_data'=>'Some Data']);
else
/* What should be the unset function? */
In Laravel 4.2, it is done with Session::forget('some_data');
or Session::flush()
. How should that be done in Laravel 5.3?
Upvotes: 11
Views: 52653
Reputation: 2427
To delete session variable in Laravel 5.6
session()->forget(['key1']);
to delete the session variables (More the one value delete from the session) use the arguments as arguments session()->forget([' ']);
session()->forget(['key1','key1','key3','...']);
Upvotes: 2
Reputation: 163748
In Laravel 5.3 you still can use flush()
and forget()
methods:
session()->flush();
session()->forget('key');
https://laravel.com/docs/5.3/session#deleting-data
Upvotes: 4
Reputation: 33186
You can use the session helper without having to use a request object.
session()->forget('some_data');
session()->flush();
Upvotes: 31