I am redirecting the page after a successful login check and the session is created but the session is not available after page redirection.
My Login Controller:
$validated = $request->validate([
'email' => 'required|email',
'password' => 'required',
'g-recaptcha-response' =>'required|captcha',
],
[
"g-recaptcha-response.required" => "Captcha is required!",
]);
if(usernamd and password matches){
session()->put("username",$username);
return redirect()->route('home');
}else{
return Redirect::to("/login")->withFail('Wrong Passoword entered.');
}
if I print the session variables, they are visible and have proper values, but when it is redirected to the home page, the session variables are not set. session()->all() is showing empty array.
I suggest you put the complete controller code. Sessions in Laravel only work with the "web" middleware defined in the App\Http\Kernel class. If you make the request from an API, you must use laravel/sanctum or manually start the sessions with the Session facade.