Skip to content

Instantly share code, notes, and snippets.

@moradi-morteza
Last active December 22, 2019 17:54
Show Gist options
  • Save moradi-morteza/b442aad0bc147b44009f72c3daf579ec to your computer and use it in GitHub Desktop.
Save moradi-morteza/b442aad0bc147b44009f72c3daf579ec to your computer and use it in GitHub Desktop.
[session] #LaravelT
// set session----------------------
session()->put('name','morteza');// or
session(['name'=>'hamid','age'=>23]);
// to get session
echo session()->get('name'); //or
echo session('name','default');
// check session---------------------
session('name',null);
session()->has('name') // return a boolean and check key and value -> so reutrn false
session('name',null);
session()->exists('name') // check justn key -> so it retrun true
// other methods----------------------
session()->all(); // save data like previous url for redirect
// delete session---------------------
$name =session()->pull('name'); // remove name from session and save value of it in $name
session()->forget('name'); // remove from session and not save or return any thing
session()->flush(); // remove all sessions
// flash session
// flash values just one save in old and if you reload page it remove - it is very good for show message
session()->flash('name','morteza');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment