I have implemented a query like this :
$categories = DB::select("SELECT categories.* FROM categories left JOIN products on products.category_root = categories.id")
->withCount('products')
->where('products_count' , '>' , 0)->get();
that mean get categories where have at least one product with category_root equal the category->id
my products table have 3 column with names : category_root
, category_parent
, category_id
and I want to check each of them in my collections.
how to get not empty categories ?
2
Answers
Using
leftJoin()
method, You can add your condition in the closure:try