Laravel 5.4中的字段验证默认消息更改 [英] Fields validation default message change in Laravel 5.4

查看:75
本文介绍了Laravel 5.4中的字段验证默认消息更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码来验证字段.

I am using this code for validating a field.

$this->validate($request, [
    'recovery_code' => 'required|exists:users,email_recovery_code',
    'new_password'=>'required',
    'confirm_password'=>'required|same:new_password',
    ]);

当我输入错误的恢复代码时,我会得到响应

and when I enter wrong recovery code i get response

"The selected recovery code is invalid"        

但我需要我的自定义消息来代替.有人知道怎么做吗?

but in place of that I want my custom message. Does anyone know how to do it?

推荐答案

很简单,就像这样:

$messages = [
        'exists' => 'Your custom message',
    ];
    $this->validate($request, [
    'recovery_code' => 'required|exists:users,email_recovery_code',
    'new_password'=>'required',
    'confirm_password'=>'required|same:new_password',
    ],$messages);

您可以在laravel中的同一字段上设置多个检查.只需将它们传递给具有不同键的数组即可.例如:存在,必需等.

You can set multiple checks on same field in laravel. Just pass them in an array with different key. e.g: exists, required, etc.

希望它对您有帮助.

干杯:)

这篇关于Laravel 5.4中的字段验证默认消息更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆