I
I
Ivan2021-08-31 17:28:14
Laravel
Ivan, 2021-08-31 17:28:14

How to exclude a specific model from the sample result through the model?

Hello. There is a sample like this:

$users = User::where('name', 'John')->orWhere('name', 'Vasja')->get()
How to exclude the model where for example from the result "last_name" = 'Doe'?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-08-31
@Djonson86

User::where(function ($query) {
    $query->where('name', 'John')
        ->orWhere('name', 'Vasja');
})
    ->where('last_name', '!=', 'Doe')
    ->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question