How to store the logged User Value in a shared variable between routes in Laravel

37 views Asked by At

i'm coding an application with laravel and since i'm still a beginner i got stuck on the login part , i didn't use the authentication library for some specefic details but now when i want to store the connected user identity values i don't know how to do it , i tried to use session variables but i always get null on them , take this as an example :

public function authenticate(Request $request)
{
    //$credentials = $request->only('Email', 'password');
    $email = Str::lower($request->input('Email'));
    $password = $request->input('password');
    $Ftime = $request->input('Ftime');
    $currentDateTime = Carbon::now();
    $user = User::where('Email', $email)->first();
    if ($currentDateTime->isAfter($Ftime)) {
        $user->update(['Password' => Str::random(60)]);

        $request->session->put(['Cuser'=>$user]);

        return redirect('login')->with('user',$user);
    }
    if ($user) {
        echo "that's it 1";
        if($user->Password == $password){
        // Authentication successful
        echo "that's it 2";
        return redirect('/home')->with('user',Auth::user());
    }
        else{
            echo "that's it 3";

            return view('errors/pass',['pass'=>$password]);
        }
    } else {
        // Authentication failed
        echo "that's it 4";
        return view('errors/email', ['error' => $email]);        
    }
}

what i want is when the user pass the password the $Cuser variable needs to be created between different routes and can be retrieved in different views

0

There are 0 answers