Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sinnbeck's avatar
Level 102

Idea for returning validation errors for specific row

I have a table with a list of projects. Each row can be saved using a save button on the row. The problem is that if the row fails validation, each row will marked as failing, as they all share the same "key". Anyone have a clever idea on how I can specify what row the validation error is on?

I am using inertia :)

0 likes
1 reply
Sinnbeck's avatar
Level 102

I found a solution, but it feels kinda hacky. I added this to my formrequest

public function withValidator(\Illuminate\Validation\Validator $validator)
    {
        $validator->after(function (\Illuminate\Validation\Validator $validator) {
            if ($validator->errors()->isNotEmpty()) {
                $validator->errors()->add('id', intval(request()->segment(3)));
            }
        });
    }

and then in react i check if errors.id matches

If anyone has a cleaner solution, I would be happy to hear it :)

Please or to participate in this conversation.