如何在laravel5.3中编辑或扩展错误消息?

时间:2016-12-01 18:41:21

标签: authentication laravel-5 eloquent

我想扩展验证设置另一个字段就像那样:

return Validator::make($data, [
    'name' => 'required|max:255',
    'email' => 'required|email|max:255|unique:users',
    'password' => 'required|min:6|confirmed',
    'another_field' => 'validation'
]); 

2 个答案:

答案 0 :(得分:0)

您可以通过documentation :)

来制作自己的验证案例

答案 1 :(得分:0)

如果您只需要更改消息,可以通过

进行更改
$messages = [
    'required' => 'The :attribute field is required.',
    'email' => 'This is a wrong e-mail address message I wrote myself.',
];

$rules = [
    'name' => 'required|max:255',
    'email' => 'required|email|max:255|unique:users',
    'password' => 'required|min:6|confirmed',
    'another_field' => 'validation'
];

return Validator::make($input, $rules, $messages);