fiter
fiter

Reputation: 773

Laravel 5.4 different value validation rule in array

I have an input with an array of entities with an ID which must be unique I've tried this:

'authors.*.id' => 'different:authors.*.id'

But it says 'The authors.0.id and authors.0.id must be different' So what is a right way to validate this?

Upvotes: 1

Views: 2100

Answers (1)

Kyslik
Kyslik

Reputation: 8385

You want to use distinct rule.

When working with arrays, the field under validation must not have any duplicate values.

'foo.*.id' => 'distinct'

Upvotes: 8

Related Questions