printing all running session variable in laravel 5.1 [duplicate]
Asked Answered
H

4

44

How do I print all running session variable in Laravel 5.1?

I want to print all the running session variable. Currently I can retrieve single running session for given value but don't know the function for print all at one time with one function something like

{{ Session::get(all)}}
Hippocampus answered 22/4, 2016 at 13:50 Comment(1)
Do you want all active sessions, or all variables in the current session?Yanirayank
D
99

If you just want to see contents of session, try dd():

dd(session()->all());

If not, just use this to get all info:

$data = session()->all();

More on this here.

Dorsal answered 22/4, 2016 at 13:53 Comment(1)
print_r(session()->all()) ; works for me, Thanks Alexey.Hippocampus
S
8

You can also use dd(Session::all());

Swear answered 14/7, 2017 at 5:1 Comment(2)
Why dont people use this syntax. Why's everybody (laraval doc too) sticking to simple query?Ira
coz helpers are simple and easy to use.Moonmoonbeam
F
2

you can display sessions contents as :

$sessions=session()->all();

or

$sessions=Session::all();

to print contents use :

foreach($sessions as $k=>$v){
    echo $k."=".$v." ";
}
//or use : 
dd(session()->all()) ; // this is  var_dump equeivelent

to use specific session key :

$user_id = session('user_id'); // key : user_id
Freewheel answered 20/4, 2022 at 13:19 Comment(0)
B
0

You can see all session by using session's all() method.

return session()->all(); // returns all session
return session()->get('name_of_session'); // returns specific session
Bergschrund answered 7/8, 2023 at 11:36 Comment(1)
both are not working in AuthServiceProvider.php file. Thanks.Tenterhook

© 2022 - 2024 — McMap. All rights reserved.