此处登录功能正常,但 $ this-> validate()功能在视图页面中不返回任何内容。尝试了其他Q& As中提出的各种方法。帮助者似乎有些不对劲。
public function postSignIn(Request $request)
{
$this->validate($request, [
'email' => 'bail|required',
'password' => 'required'
]);
if (Auth::attempt([ 'email' => $request['email'], 'password' => $request['password'] ])){
return redirect()->route('dashboard');
}
return redirect()->back();
}
@if ($errors->any())
<div>
<ul>
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
</div>
@endif
<form name="loginForm" action="{{ route('signin') }}" method="post" autocomplete="disable">
<div class="form-group mb-4">
<input type="email" class="form-control {{ $errors->has('email')? 'is-invalid' : ''}}" name="email" aria-describedby="emailHelp" placeholder=" " />
<label for="loginFormInputEmail">Email address</label>
</div>
<div class="form-group mb-4">
<input type="password" class="form-control {{ $errors->has('password')? 'is-invalid' : ''}}" name="password" placeholder="Password" />
<label for="loginFormInputPassword">Password</label>
</div>
答案 0 :(得分:0)
可能另一个问题是$ errors错误未被保存到Session变量$ errors并且视图中没有显示任何内容。
以下是同一问题的示例:http://laravel.io/forum/03-28-2016-errors-variable-empty-after-failed-validation
对我来说,上面链接中定义的解决方案是有效的。解决方案:在app \ Http \ Kernel.php中移动\ Illuminate \ Session \ Middleware \ StartSession :: class,从$ middlewareGroups到$ middleware
<强>之前强>
来源Thrade :Laravel MessageBag errors array is empty in view but with content if I kill script