06.10.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Session 446<br />

1 $value = $request->session()->get('key', 'default');<br />

2<br />

3 $value = $request->session()->get('key', function() {<br />

4 return 'default';<br />

5 });<br />

If you would like to retrieve all data from the session, you may use the all method:<br />

1 $data = $request->session()->all();<br />

You may also use the global session PHP function to retrieve and store data in the session:<br />

1 Route::get('home', function () {<br />

2 // Retrieve a piece of data from the session...<br />

3 $value = session('key');<br />

4<br />

5 // Store a piece of data in the session...<br />

6 session(['key' => 'value']);<br />

7 });<br />

Determining If An Item Exists In The Session<br />

To determine if a value is present in the session, you may use the has method. The has method<br />

returns true if the value is present and is not null:<br />

1 if ($request->session()->has('users')) {<br />

2 //<br />

3 }<br />

To determine if a value is present in the session, regardless of its value, you may use the exists<br />

method. The exists method returns true if the value is present:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!