41

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)}}
1
  • Do you want all active sessions, or all variables in the current session?
    – Jerodev
    Apr 22, 2016 at 14:14

4 Answers 4

97

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.

1
  • 4
    print_r(session()->all()) ; works for me, Thanks Alexey. Apr 22, 2016 at 14:30
9

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

2
  • Why dont people use this syntax. Why's everybody (laraval doc too) sticking to simple query? Sep 25, 2020 at 6:02
  • coz helpers are simple and easy to use.
    – Leutecia
    May 3, 2022 at 4:18
3

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
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.