首页 > 解决方案 > 我的 Laravel Auth::attempt() 函数不起作用

问题描述

这是我的控制器

 if($request->isMethod('post')){
        $data = $request->input();
        if(Auth::attempt(['email'=>$data['username'],'password'=>$data['password'],'user_type'=>'2'])){                
            return redirect('/business/dashboard');

标签: phplaravelauthentication

解决方案


尝试使用此代码:如果 user_type 列类型为整数,则给出不带引号的 2 否则相同的代码和密码必须是 hash::make 否则 auth::attempt 将不起作用。

     if($request->isMethod('post')){
     $user = User::where(['email'=>$request['username'],'user_type'=>'2'])->first();
    if(!empty($user)){
 if(Auth::attempt(['email'=>$request['username'],'password'=>$request['password']])){                
        return redirect('/business/dashboard');
    }
   abort(404);

推荐阅读