When I write this line of code of my controller
public function cartAdd(Request $request){
$request->session()->put('key', 'value 1');
$output = $request->session()->get('key');
dd($output);
}
Then output "value 1"
But when I comment one line code which set the session value
public function cartAdd(Request $request){
// $request->session()->put('key', 'value 1');
$output = $request->session()->get('key');
dd($output);
}
Then output
"this is key 1"
This is my previous session value. What's wrong with this. This time output should be "value 1"
I found two solutions.
Remove dd() method. Because of dd() request not complete and it's not working.
Save the session using $request->session()->save(); .