如何在Laravel中本地化字段名称?

时间:2016-12-10 06:36:34

标签: laravel laravel-5.3

例如,我对HTML表单进行了验证:

 $validator = Validator::make($request->all(), [
            "code" => "required|string|size:10"]);

如果我收到错误,请看:

The code field is required.

Wrere code是字段名称。

我如何翻译(本地化)这个?

1 个答案:

答案 0 :(得分:4)

您可以在make方法中传递第三个参数:

$rules = [
    "code" => "required|string|size:10",
];

$messages = [
    'required' => 'The :attribute field is required.',
];

$validator = Validator::make($input, $rules, $messages);
  

详细了解Custom Validation Error Messages

跳这个有帮助!