【问题标题】:Method validateConfirm does not exist (Laravel)方法 validateConfirm 不存在(Laravel)
【发布时间】:2018-01-20 17:19:38
【问题描述】:

我正在关注 Dayle Rees 的 Laravel 教程,尝试构建一个简单的注册页面。

如果我提交带有验证错误的注册表单,页面会重新加载并显示验证错误。但是,当我输入正确的值并提交时,我收到以下错误 -

BadMethodCallException
Method [validateConfirm] does not exist.

这是我的 register.blade.php -

<!doctype html>
<html lang="en">
<head>

</head>
<body>

<h1>Registration form</h1>

{{ Form::open(array('url' => '/registration')) }}

    {{-- Username field. ------------------------}}
    {{ Form::label('username', 'Username') }}
    {{ Form::text('username') }}
    {{ $errors->first('username', '<span class="error">:message</span>') }}
<br/>
    {{-- Email address field. -------------------}}
    {{ Form::label('email', 'Email address') }}
    {{ Form::email('email') }}
    {{ $errors->first('email', '<span class="error">:message</span>') }}
<br/>
    {{-- Password field. ------------------------}}
    {{ Form::label('password', 'Password') }}
    {{ Form::password('password') }}
    {{ $errors->first('password', '<span class="error">:message</span>') }}
<br/>
    {{-- Password confirmation field. -----------}}
    {{ Form::label('password_confirmation', 'Password confirmation') }}
    {{ Form::password('password_confirmation') }}
<br/>
    {{-- Form submit button. --------------------}}
    {{ Form::submit('Register') }}

{{ Form::close() }}
</body>
</html>

这是我的 routes.php [注意:如果我删除密码规则,问题就会消失]

Route::get('/', function()
{
    return View::make('register');

});

Route::post('/registration', function()
{
    // Fetch all request data.
    $data = Input::all();

    // Build the validation constraint set.
    $rules = array(
        'username'   => 'required|min:3|max:32',
        'email'      => 'required|email',
        'password'   => 'required|confirm|min:3'
    );

    // Create a new validator instance.
    $validator = Validator::make($data, $rules);

    if ($validator->passes()) {
        // Normally we would do something with the data.
        return 'Data was saved.';
    }

    return Redirect::to('/')->withErrors($validator);
});

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    问题似乎是由于使用confirm 而不是confirmed。解决了!

    【讨论】:

    • 我正在尝试做密码提醒的东西,我的错误说方法 [validatePassword] 不存在。我不知道哪里做错了。
    【解决方案2】:

    您可以包含-&gt;back() 或使用

    必须在您的代码中更改,这是必需的

       return Redirect::to('/')
                         ->back()
                         ->withErrors($validator);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 2016-10-28
      • 2020-03-20
      • 2018-06-17
      • 2019-04-11
      • 2018-09-28
      • 2019-07-01
      相关资源
      最近更新 更多