What is the real difference between Laravel's session() and request()->session()?

Viewed 5052

I am working on a Laravel(5.2) project that heavily relies on session, quite new though but I was just curious what difference global session() and Http request()->session() has apart from the fact that they have different means of accessing and writing into session?

Here are the few information I have about this from laravel 5.4 doc,

enter image description here

Unfortunately, this does not really make me understand the difference. I have as well googled and stackoverflowed perhaps I could find an answer to no avail. Example is laravel difference of session::flash and request->session->flash but I am not so comfortable with the answer

What is the real difference they have in managing session data? I wouldn't mind a reference to a documentation where this is or even if I have to dig into laravel core.

Thanks

3 Answers

Unfortunately the best answer has already been given by the Laravel note; and I can only attest to that for now cos I have noticed such situation once.

I couldn't understand why global session('key') refuse to echo the value of $request->session()->put('key', 'value') within the same method. Hopefully I'd come across the situation again just for proof but the last response I'd want to give you is:

"There are no differences, it's just a shortcut."

Cos just like the docs mentioned, there's difference notable in practice

Related