【问题标题】:How to show error message with dynamic value in Laravel array validation如何在 Laravel 数组验证中显示具有动态值的错误消息
【发布时间】:2019-03-26 03:39:51
【问题描述】:

我使用的是 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.1、student_id.2... 就像我在第一个输入字段中输入了111-111 然后我想显示111-111 is not exists.

【问题讨论】:

    标签: laravel laravel-5 laravel-validation


    【解决方案1】:

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

    'student_id' => 'The value of :attribute is :input which is invalid.',
    

    【讨论】:

    • 我不清楚答案。你能帮我理解吗
    猜你喜欢
    • 2022-11-12
    • 2021-12-19
    • 1970-01-01
    • 2017-01-06
    • 2018-11-05
    • 2017-04-24
    • 2014-08-22
    • 2019-11-11
    • 2017-10-28
    相关资源
    最近更新 更多