What is the difference between the Session::set
and Session::put
methods in Laravel? The docs only covers Session::put
, but I have seen set
used instead.
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.
The correct syntax for this is: Session::set('variableName', $value); For Laravel 5.4 and later, the correct method to use is put : Session::put('variableName', $value);
The session configuration is stored in config/session. php . Be sure to review the well documented options available to you in this file. By default, Laravel is configured to use the file session driver, which will work well for the majority of applications.
They are exactly the same. Session::put
directly calls Session::set
.
The only difference, is that Session::put
allows you to pass it an array of [key => value]
pairs, in which case it calls Session::set
for each of them.
These methods are defined in Illuminate\Session\Store
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