Search code examples
phplaravellaravel-validation

Laravel set validation message to Array Field?


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.


Solution

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

    and use this :

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