How to store session in larvel 5.7
I use laravel 5.6 $value = session('key', 'default'); and I check session()->has('key') it working fine but when I use 5.7 its not working.
session()->put('key', 'value');
=> null
session()->has('key');
=> true
$value = session('key', 'default');
=> "value"
Are you saying that the last function is returning 'default' instead of 'value'?
@PATRICKSJ - Only I need its
session()->has('key');
=> true or => false
You can use facade also:
Session::has('key')
might be works
@HDSAVANI - Thanks for reply but I also used not working.
i think you can try to use session facade to put and check both:
\Session::put('key', 'value');
\Session::has('key')
You can try this way
Could you be more specific that "not working" ?
@VILFAGO - Actually I need store a session for check canvas menu
Laravel Code controller code
//Controller Code
if ( Session::has('sidebarState')) {
session::forget('sidebarState');
} else {
//colapse sidebar
session::put('sidebarState', 'sidebar-collapse');
}
// View Code
<body class="hold-transition skin-blue sidebar-mini {{ Session::get('sidebarState') }}"></body>
and ?
You get an error ?
Nothing appaears ?
Sthing appears, but not what you expect ?
What is your session driver ?
if(session()->has('sidebarState')) {
session()->forget('sidebarState');
} else {
//colapse sidebar
session()->put('sidebarState', 'sidebar-collapse');
}
}
// View Code
<body class="hold-transition skin-blue sidebar-mini {{ session('sidebarState') }}"></body>
or closer to the doc, with the $request
if($request->session()->has('sidebarState')) {
$request->session()->forget('sidebarState');
} else {
//colapse sidebar
$request->session()->put('sidebarState', 'sidebar-collapse');
}
}
Please or to participate in this conversation.