本文介绍了Laravel 密码Password_Confirmation 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用它来编辑用户帐户信息:

I've been using this in order to edit the User Account Info:

$this->validate($request, [
    'password' => 'min:6',
    'password_confirmation' => 'required_with:password|same:password|min:6'
]);

这在 Laravel 5.2 应用程序中运行良好,但在 5.4 应用程序中不起作用.

This worked fine in a Laravel 5.2 Application but does not work in a 5.4 Application.

这里出了什么问题,或者只有在 passwordpassword_confirmation 字段为设置好了吗?

What's wrong here, or what is the correct way in order to only make the password required if either the password or password_confirmation field is set?

推荐答案

您可以使用 确认验证规则.

You can use the confirmed validation rule.

$this->validate($request, [
    'name' => 'required|min:3|max:50',
    'email' => 'email',
    'vat_number' => 'max:13',
    'password' => 'required|confirmed|min:6',
]);

这篇关于Laravel 密码Password_Confirmation 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 23:33