auth attempt laravel 8 with status 1

You just take user status and check user status is true or false. You can take status using Auth::User()->status from auth session. Try this.

public function login(Request $request)
    {
        $request->validate([
            'email' => 'required',
            'password' => 'required',
        ]);
        if(Auth::attempt(['email'=>$request->email,'password'=>$request->password])){
            $userStatus = Auth::User()->status;
            if($userStatus=='1') {
                return redirect()->intended(url('dashboard'));
            }else{
                Auth::logout();
                Session::flush();
                return redirect(url('login'))->withInput()->with('success','You are temporary blocked. please contact to admin');
            }
        }
        else {

            return redirect(url('login'))->withInput()->with('success','Incorrect username or password. Please try again.');
        }
        
         
    }


Leave a Reply