我有一个 laravel 项目,在兰花中有一个管理面板,我更改了授权,但遇到了问题。我需要在登录时收到特定错误,但该怎么做?代码如下所示:
public function login(Request $request)
{
$credentials = $request->validate([
'email' => ['required', 'email'],
'password' => ['required', 'string'],
]);
$auth = $this->guard->attempt([
'email' => $credentials['email'],
'password' => $credentials['password'],
'status' => User::$status['active']
], $request->filled('remember'));
if ($auth) {
return $this->sendLoginResponse($request);
}
throw ValidationException::withMessages([
'email' => __('The details you entered did not match our records. Please double-check and try again.'),
'password' => __('auth.password'),
'status' => __('auth.status')
]);
}
现在如果有任何错误,那么我会收到所有 3 个错误。如何使用 attemp 方法找出具体错误是什么?或者我需要以不同的方式授权吗?
总的来说,我决定这样做:
似乎有效