1

How to set custom validation message to array file like.

$validationRules = [
    'attrtitle[]' => 'required|max:255',
];

i try code for set message but not working.

protected $messages = [
    'attrtitle[]:required' => 'Please Select Attributes.'
];

// OR //

protected $messages = [
    'attrtitle:required' => 'Please Select Attributes.'
];

my html field for attrtitle is

<select name='attrtitle[]' multiple>
  <option value=''>Select Value</option>
  <option value='1'>1</option>
  <option value='2'>2</option>
  <option value='3'>3</option>
</select>

i try both but not working how can i set custom message for attrtitle field please help thanks.

2 Answers 2

2

just you need to add . instead of : sign like.

and use this :

protected $messages = [
    'attrtitle[].required' => 'Please Select Attributes.'
];
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for being offtopic, but it would be perfect to stick index number into message itself... like Please Select Attributes (array index number). Do you have an Idea how to do that?
0

try this :

$messages = [
    'attrtitle.required' => 'Please Select Attributes.'
];

In your controller and then add it to your validate method like this :

$this->validate($request, $validationRules, $messages);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.