I am using Laravel's validator but I am having trouble figuring out how to modify the validator to display the index of the array which contains an error. My input rows are named as rows[indexNumberGoesHere][indexNameGoesHere]
.
As of now, I am going about the validation very simply:
$data = $request->validate([ 'rows.*.title' => 'required', 'rows.*.price' => 'required', 'rows.*.quantity' => 'required', 'rows.*.discount' => 'nullable', 'rows.*.description' => 'nullable', 'rows.*.taxable' => 'nullable', ]);
How can I go about using Laravel's validator to display a custom message to tell the user which exactly field contains an error? As of now, if the first title is empty, it returns the error: The rows.0.title field is required.
I would like to be able to customize the error text to say something like Row 1: Please fill in the title field.
Thanks in advance.
https://stackoverflow.com/questions/65866613/display-index-of-array-that-contains-error-when-using-laravel-validator January 24, 2021 at 10:27AM
没有评论:
发表评论