我可以像这个突出显示的那样记录我的第二个用户
但是第一个,我无法登录,这是我的代码
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
字段
这是扩展的
狐的传说