tempra
tempra

Reputation: 2331

How to validate array by themselves? (laravel)

I have an array of data for example in which they have the same id.

[
    {
        id: 222,
        name: 'Fff',
    }
    {
        id: 223,
        name: 'Ssss',
    },
    {
        id: 222,
        name: Wwww',
    }
]

From the data above, the expected behavior is, it should fail because they have the same id.

Is there a Laravel built-in validation in which we can validate this scenario?

Upvotes: 0

Views: 62

Answers (1)

Shahrukh
Shahrukh

Reputation: 478

Yes there is a validation called distinct to check for duplicate values. For more info https://laravel.com/docs/7.x/validation#rule-distinct

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

Upvotes: 3

Related Questions