Laravel 5.2 Login With Condition

后端 未结 3 913
礼貌的吻别
礼貌的吻别 2021-01-26 06:51

So, I have users table which is default by laravel. But I add a new column named \'status\'.
So the columns on the users table are id, name, email, password, remember_token

相关标签:
3条回答
  • 2021-01-26 07:14

    You can override the authenticated() method in App\Http\Controllers\Auth\LoginController to add logic after the user is authenticated:

       protected function authenticated($request,$user)
        {
            if(\Auth::user()->status){
                return redirect('/admin'); 
            }
    
            return redirect('/home');   
        }
    
    0 讨论(0)
  • 2021-01-26 07:20

    If its all default laravel authentication then you should be able to do

    ( Auth::user()->status === 0 ) ? 'do something' : 'do something else';
    
    0 讨论(0)
  • 2021-01-26 07:28

    By default, The laravel redirect to "authenticated" function after login. So you can add "authenticated" function in "LoginController". In the "authenticated" function will get the user object.

    protected function authenticated(Request $request, $user)
    {
        if (!$user->status == 1) {
            return redirect('admin');
        }
        return redirect('web');
    }
    
    0 讨论(0)
提交回复
热议问题