lundi 14 novembre 2016

Getting the index of a list and display in error message during validation in Laravel

I have a validation rule as follows. I'm using the validate method via the ValidateRequests trait.

$this->validate($request, [
    'entries'                 => 'required|max:5',
    'entries.*.name'          => 'required',
    'entries.*.email'         => 'required|email',
    'entries.*.mobile_number' => 'required'
]);

And these are some sample error messages that I've encountered.

[
    'entries.0.name'  => ['The entries.0.name is required.'],
    'entries.1.email' => ['The entries.1.email must be a valid email address.']
]

Is there a way to modify the message to these by using only the validation.php in modifying such messages?

[
    'entries.0.name'  => ['Line 0 - The name is required.'],
    'entries.1.email' => ['Line 1 - The email must be a valid email address.']
]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire