我可以像这个突出显示的那样记录我的第二个用户但是第一个,我无法登录,这是我的代码public function postLogin(Request $request) { // -> Validate the request. $this->validate(request(), [ 'pin' => 'required|string', 'password' => 'required|string', ]); $pin = request()->get('pin'); $field = filter_var(request()->get('pin'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; $remember_me = request()->get('remember'); $password = request()->get('password'); $user = User::where("${field}",'=',$pin)->first(); // dd($user); if ( is_null($user->confirmed_at) || $user->status === "0") { return redirect()->back()->with('flash-message','The account you tried to login was either not yet confirmed by you or activated by one of our admins.'); } else { if (Auth::attempt([$field => $pin ,'password' => $password])){ // dd(auth()->user()->role_id); switch(auth()->user()->role_id){ /*the roles would be determined*/ case 1 : return redirect()->route("admin.dashboard"); case 2 : return redirect()->route("admin.dashboard"); case 3 : return redirect()->to('/'); } } } }登录后我得到一个白屏,当我 dd 结果时 $user = User::where("${field}",'=',$pin)->first();我明白了 状态字段是一个enum字段这是扩展的
1 回答
狐的传说
TA贡献1804条经验 获得超3个赞
看起来您的密码不正确,因为您没有处理这种情况。那将解释一个空白屏幕。尝试添加这样的东西,看看它是否进入那里。
if (Auth::attempt([$field => $pin ,'password' => $password])){
// dd(auth()->user()->role_id);
switch(auth()->user()->role_id){
/*the roles would be determined*/
case 1 : return redirect()->route("admin.dashboard");
case 2 : return redirect()->route("admin.dashboard");
case 3 : return redirect()->to('/');
}
} else {
dd('Auth failed!');
}
- 1 回答
- 0 关注
- 106 浏览
添加回答
举报
0/150
提交
取消