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,
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
Sessions are used to store information about the user across the requests. Laravel provides various drivers like file, cookie, apc, array, Memcached, Redis, and database to handle session data. By default, file driver is used because it is lightweight. Session can be configured in the file stored at config/session.
If you want to increase your session life time then we need to change in . env file and it is very easy to change it from configuration file in laravel. laravel provides you session. php file there is we can see 'lifetime' key option for setting time in minutes.
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.
session() is a helper that gives you a faster access to request()->session()
Note that request() is also a helper that gives you a faster access to the request object.
There are no differences, it's just a shortcut.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With