A
A
Alexander Shapoval2016-08-16 17:57:00
Laravel
Alexander Shapoval, 2016-08-16 17:57:00

Complex search query to the database in Laravel. How to exclude deleted records?

In general, records that have been deleted through soft delete are stored in the table.
I make a query to the database

where('name', 'LIKE', '%' . $slug . '%')->
orWhere('short_description', 'LIKE', '%' . $slug . '%')->
orWhere('description', 'LIKE', '%' . $slug . '%')->
orWhere('meta_keywords', 'LIKE', '%' . $slug . '%')->

Everything is fine, only how to write here For it also displays deleted records Thank you for your help!
whereNull('deleted_at')->

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2016-08-16
@AlexanderShapoval

I wrote on my knee, it must be something like this.

->where(function ($query) use ($slug) {
    $query->where('name', 'LIKE', '%' . $slug . '%');
    $query->orWhere('short_description', 'LIKE', '%' . $slug . '%');
    $query->orWhere('description', 'LIKE', '%' . $slug . '%');
    $query->orWhere('meta_keywords', 'LIKE', '%' . $slug . '%');
})
->whereNull('deleted_at');

S
Stanislav Pochepko, 2016-08-16
@DJZT

More or less like this

where(function($q){
    $q->where('name', 'LIKE', '%' . $slug . '%')->
    orWhere('short_description', 'LIKE', '%' . $slug . '%')->
    orWhere('description', 'LIKE', '%' . $slug . '%')->
    orWhere('meta_keywords', 'LIKE', '%' . $slug . '%')->
})->whereNull()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question