Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tanmay_das's avatar

How to delete session data?

The official documentation suggests that there are two ways to handle session in laravel. I am trying the global-session-helper way. But in the delete data section (https://laravel.com/docs/5.4/session#deleting-data) it only shows how to delete via the $request instance.

How can I delete a session data that I stored using session(['key' => 'value']);?

0 likes
6 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

$request->session()->forget('key');

1 like
tanmay_das's avatar

Does that mean there isn't any other way than using a $request instance? If one can store data without $request instance, he should also be able to delete the data without $request object.

jlrdw's avatar

The helper in background uses $request, I'd stay consistent and just use $request.

Snapey's avatar

I get your point, but a session does not exist without a request?

There should be no problem in doing it as suggested.

if this still does not sit well with you then use session(['key' => null]); ?

1 like
tanmay_das's avatar

Well, then I think calling session()->forget('key'); has the same effect as calling $request->session()->forget('key');

Snapey's avatar

Knowing the detail Taylor goes to, I decided to check.

The session() helper returns an instance of the session manager, so these are valid;

session()->put('key', 'value');

session()->forget('key');

2 likes

Please or to participate in this conversation.