vendredi 28 avril 2017

How does sessions work in Laravel 5

I am trying to understand how sessions work in Laravel 5(.4). In one hand there are two ways of using them as described in the official documentation:

There are two primary ways of working with session data in Laravel: the global session helper and via a Request instance.

$request->session()->put('key', 'default');

and

session('key', 'default');

The documentation says:

There is little practical difference between using the session via an HTTP request instance versus using the global session helper.

But it is never explained what the difference is.

In the other hand there is the "Facade way":

Session::put('key', 'value');

And recently I found this Stack Overflow question How to use session in laravel 5.2 controller. train_fox pointed out this way:

session()->put('key', 'default');

So that makes a total of four ways. And I cannot figure out why or when use one or another.

By the way, the only way I could get sessions to work with Redis was with the two last ways.

Thank you in advance for your enlightenment.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2paRqCk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire