2 回答
TA贡献1836条经验 获得超3个赞
我是这样想出来的(非常相似):
protected function validateLogin(Request $request)
{
$validator = Validator::make($request->all(), [
$this->username() => 'required|string',
'password' => 'required|string',
]);
if ($validator->fails()) {
throw (new ValidationException($validator))->redirectTo(route('login'));
}
}
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
])->redirectTo(route('login'));
}
需要抛出异常,validateLogin因为只返回重定向什么都不做。
TA贡献2039条经验 获得超7个赞
您可以通过覆盖控制器上的validateLogin和sendFailedLoginResponse功能来解决此问题。
protected function validateLogin(Request $request)
{
$validator = Validator::make($request->all(), [
$this->username() => 'required|string',
'password' => 'required|string',
]);
if ($validator->fails()) {
return redirect('login')
->withErrors($validator)
->withInput();
}
}
protected function sendFailedLoginResponse(Request $request)
{
throw new ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
])->redirectTo(route('login'));
}
- 2 回答
- 0 关注
- 78 浏览
添加回答
举报