如何在Laravel数组验证中显示带有动态值的错误消息

问题描述 投票:1回答:1

我正在使用Laravel版本5.4。我正在验证一个数组,但它默认显示一条错误消息。我想显示验证失败的消息。

这是我的数组输入字段。

<input readonly type="text" id="users-id" name="student_id[]" placeholder="{{ $details->batch_id }}" value="{{ $details->batch_id}}" class="form-control input-border" required>

我正在验证控制器中的数组。

'student_id.*'=> 'required|exists:studentinfo,batch_id|distinct|unique:student_projects,student_batchid',

当任何验证失败时,它会向我显示这样的错误。

鉴于student_id.1不存在。鉴于student_id.2不存在。

我想显示输入数据而不是student_id.1student_id.2 ...就像我在我的第一个输入字段中输入111-111然后我想要显示111-111 is not exists.

laravel laravel-5 laravel-validation
1个回答
1
投票

您可以在语言文件中指定自定义消息,而不是直接将其传递给Validator。为此,请将您的消息添加到resources / lang / xx / validation.php语言文件中的自定义数组中。要显示属性的值,请使用:input

'student_id' => 'The value of :attribute is :input which is invalid.',
© www.soinside.com 2019 - 2024. All rights reserved.