验证函数不能在laravel表单验证Laravel 5.2中工作

时间:2018-03-26 20:27:53

标签: php laravel validation laravel-5.2 helpers

此处登录功能正常,但 $ this-> validate()功能在视图页面中不返回任何内容。尝试了其他Q& As中提出的各种方法。帮助者似乎有些不对劲。

UserController中

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>

1 个答案:

答案 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

<强>之前

enter image description here

<强>后 enter image description here

来源Thrade Laravel MessageBag errors array is empty in view but with content if I kill script