Answer the question
In order to leave comments, you need to log in
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 . '%')->
whereNull('deleted_at')->
Answer the question
In order to leave comments, you need to log in
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');
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 questionAsk a Question
731 491 924 answers to any question