2

I am using Laravel version 5.4. I'm validating an array but it's showing an error message by default. I want to show a message for failed validations.

Here is my array input field.

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

I am validating the array in the controller.

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

When any validation fails it shows me an error like this.

Given student_id.1 is not exists. Given student_id.2 is not exists.

I want to show input data instead of student_id.1, student_id.2... Like I have inputted 111-111 in my first input field then I want to show 111-111 is not exists.

1 Answer 1

2

You can specify a custom message in a language file instead of passing it directly to the Validator. To do so, add your messages to custom array in the resources/lang/xx/validation.php language file. To display the value of an attribute use :input.

'student_id' => 'The value of :attribute is :input which is invalid.',
1
  • Answer is not clear to me. Can you please help me to understand
    – Fokrule
    Commented Jun 1, 2018 at 17:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.