Laravel 5确认错误信息显示在错误字段中

Laravel 5确认错误信息显示在错误字段中,laravel,laravel-5,laravel-validation,Laravel,Laravel 5,Laravel Validation,我想检查我的代码中是否有我没有意识到的错误,但为什么我的确认字段的错误消息一直显示在错误的字段中?假设我有一个密码字段和一个密码确认字段,但每当用户在密码确认字段中出错时,错误就会显示在密码字段中。下面是错误的屏幕截图 下面是我如何使用FormRequest验证输入的: public function rules() { $rules = [ 'login_email' => 'required', 'g-recaptcha-response

我想检查我的代码中是否有我没有意识到的错误,但为什么我的确认字段的错误消息一直显示在错误的字段中?假设我有一个密码字段和一个密码确认字段,但每当用户在密码确认字段中出错时,错误就会显示在密码字段中。下面是错误的屏幕截图

下面是我如何使用FormRequest验证输入的:

public function rules()
{
    $rules = [
    'login_email'           =>  'required',
    'g-recaptcha-response'  =>  'required|captcha',
    ];

    if ($this->request->has('password'))
    {
        $rules = [
        'password' => 'required|confirmed|between:6,200',
        'password_confirmation' => 'required',
        'g-recaptcha-response'  =>  'required|captcha',
        ];
    }

    if ($this->request->has('old_password'))
    {
        $rules = [
        'old_password' => 'required|between:6,200',
        'password' => 'required|confirmed|between:6,200',
        'password_confirmation' => 'required',
        'g-recaptcha-response'  =>  'required|captcha',
        ];
    }

    return $rules;
}
最后,这是我的html代码

{!! Form::open(array('class' => 'form-horizontal login-form', 'url' => URL::route('postReset'), 'method' => 'POST')) !!}
            <div class="form-group">
                <div class="col-md-12 col-sm-12">
                    {!! Form::password('password', array('class' => 'form-control', 'placeholder' => 'New Password*')); !!}
                    {!! MessagerService::setInlineError($errors->first('password')) !!}
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12 col-sm-12">
                    {!! Form::password('password_confirmation', array('class' => 'form-control', 'placeholder' => 'Retype New Password*')); !!}
                    {!! MessagerService::setInlineError($errors->first('password_confirmation')) !!}
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-12 col-sm-12">
                    {!! app('captcha')->display(); !!}
                    {!! MessagerService::setInlineError($errors->first('g-recaptcha-response')) !!}
                </div>
            </div>                  

            <div class="form-group">
                <div class="col-md-12 col-sm-12">
                    <button type="submit" class="btn btn-primary cbtn-login">Reset Password</button>
                </div>
            </div>

            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <input type="hidden" name="hash" value="{{ Session::get('hash') }}">
{!! Form::close() !!}
{!!表单::打开(数组('class'=>'表单水平登录表单','url'=>url::路由('postReset'),'method'=>'POST'))
{!!Form::password('password',array('class'=>'表单控件','placeholder'=>'新密码*');!!}
{!!MessagerService::setInlineError($errors->first('password'))
{!!Form::password('password_confirmation',array('class'=>'表单控件','placeholder'=>'重新键入新密码*');!!}
{!!MessagerService::setInlineError($errors->first('password_confirmation'))
{!!app('captcha')->display();!!}
{!!MessagerService::setInlineError($errors->first('g-recaptcha-response'))
重置密码
{!!Form::close()!!}

因为您已经为密码字段定义了确认规则,所有与密码确认相关的错误也将显示在密码字段中。

在这种情况下我该怎么办?我无法将确认规则更改为密码确认字段,否则它将无法验证。您应该从密码错误列表中取出“密码确认不匹配”,并在密码确认字段中显示它。您从何处获得此类<代码>消息服务