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

jinsonjose's avatar

how to set a session variable in laravel login time and how to get that session variable in laravel api

how to set a session variable in laravel login time and how to get that session variable in laravel api

in my api routes are protect using laravel passport method

i am developing laravel application with vuejs

my concern is that i want to set a variable on globally in login time and i want to check that value every time also some time i want to change that value

0 likes
4 replies
prasadchinwal5's avatar

You can store the data in session by $request->session()->put('key', 'value'); or by using global helper $request->session()->put('key', 'value');

You can retrieve session values by $value = $request->session()->get('key'); or by using global helper $value = session('key', 'default');

More on sessions in Laravel Docs

Snapey's avatar

How are you 'logging in'. Bear in mind that you must be talking about the same session.

By default api routes are stateless, so there can be no session.

Please or to participate in this conversation.