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

Verdemis's avatar

Validation: unique fields in an request array

Hello everyone,

I have a list of products a user can edit. When he saves his changes I want to validate his entries. The field 'artNo' has to be unique in the products table. Normally I would just use the following rule:

$rules = [
            'item.*.artNo' => ['required',
            Rule::unique('products')->ignore($id)]
];

But now I have an array with multiple IDs. Is there a way to give this rule the ID of the product which is currently validating?

My request looks like this

$request->item[$idOfTheProduct]['artNo'];

Best, Sascha

0 likes
0 replies

Please or to participate in this conversation.