47

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? Commented Apr 22, 2016 at 14:14

4 Answers 4

102

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.

Sign up to request clarification or add additional context in comments.

1 Comment

print_r(session()->all()) ; works for me, Thanks Alexey.
8

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

2 Comments

Why dont people use this syntax. Why's everybody (laraval doc too) sticking to simple query?
coz helpers are simple and easy to use.
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

Comments

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

1 Comment

both are not working in AuthServiceProvider.php file. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.