K
K
kaxa32012020-01-17 16:48:15
Laravel
kaxa3201, 2020-01-17 16:48:15

How to make validation for uniqueness plus a few more conditions?

There is a validator

$validator = Validator::make($data, [
                        'id' => 'unique:mongodb.users,id',
                    ], [
                        'status_code.unique' => 'error',
                    ]);

Can I add an additional condition here?
I want to check for uniqueness, but if this record does not have deleted_at

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2020-01-17
@Fragster

but if this entry does not have deleted_at

That's how it works by default, right? The global scope is just with such a selection.
If in the model
{
    use SoftDeletes;
}
of course spelled out

J
jazzus, 2020-01-17
@jazzus

Can it be like this

Rule::unique('users')->where(function ($query) {
    return $query->whereNull('field');
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question