Laravel Session
15 - Oct - 2021
XpertPhp
28
What is the use of session in laravel?
In the laravel, Session is one type of mechanism. which used to store information. we can use multiple driver way to store data like as file, cookie, APC, array, Memcached, Redis, and database. but laravel default use as file driver.Laravel session set value
We can set data in session using the put() method and it takes two arguments such as key and value.$request->session()->put('key', 'value');
Laravel session get value
We can get data in session using the get() method and it takes one argument such as a key.$data = $request->session()->get('key');
Laravel delete session value
If you want to delete data from the session using the forget() method and it takes one argument such as a key.$request->session()->forget('key');
delete all session in laravel
If you want to delete all data from the session using the flush() method and it takes one argument such as a key.$request->session()->flush();
add array in session laravel
We can add array data in session using the push() method and it takes two arguments such as key and array variable.$request->session()->push('key',$add_arr);