Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Session::set and Session::put in Laravel?

Tags:

laravel

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.

like image 604
Benubird Avatar asked Apr 10 '15 10:04

Benubird


People also ask

What is session() in Laravel?

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.

How to put value in session in Laravel?

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);

Where to set session in Laravel?

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.


1 Answers

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

like image 174
Benubird Avatar answered Oct 05 '22 13:10

Benubird