方法 validateConfirm 不存在(Laravel)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22055846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:06:18  来源:igfitidea点击:

Method validateConfirm does not exist (Laravel)

phplaravel

提问by Sainath Krishnan

I am following Dayle Rees' Laravel tutorial, trying to build a simple registration page.

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

If I submit the registration form with validation errors, the page reloads and shows me the validation errors. However, when I key in correct values and submit, I get the following error -

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

BadMethodCallException
Method [validateConfirm] does not exist.

This is my register.blade.php -

这是我的 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>

And this is my routes.php [NOTE : The issue goes away if I remove the rule for password]

这是我的 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);
});

回答by Sainath Krishnan

Issue seems to be due to using confirminstead of confirmed. Resolved!

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

回答by Sainath Krishnan

you can include ->back()or use

你可以包括->back()或使用

must be changed in your code , its required

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

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