johncarter
5 days ago
116
8
Laravel

Change validation message :attribute placeholder for array inputs

Posted 5 days ago by johncarter

I have a nested array of inputs being posted to a controller.

$validatedData = request()->validate([
    'line.*.image' => 'image|max:500',
    'line.*.description' => 'required',
    'line.*.retail_price' => 'min:0|required',
    'line.*.quantity' => 'min:1|required',
]);

When validation fails I receive an error message that looks like this:

The line.0.retail_price field is required.

How do I replace that to read something like:

The retail price on line 1 is required.

Please sign in or create an account to participate in this conversation.