vendredi 30 novembre 2018

Laravel validation: unique rule to bring duplicated record back

I have not found anywhere a clean way of what I am exactly looking for so thought to give on here a try:

$validator = Validator::make($request->all(), [
            'an_id' => 'unique:users,an_id',
            'another_id' => 'unique:users,another_id',
            'test_id' => 'unique:users,test_id',
        ]);

        if ($validator->fails()) {
            //
        }

So, what I'd like to do is when a duplicate test_id is provided, is to not only fail but show me which user uses the same test_id.

Is this actually possible through Laravel's Validation?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire