Support the ongoing development of →
Database Eloquent
Last updated 1 year ago.

I've not heard of this option whereIfIsNotEmpty, but if category is null (empty) you could use whereNotNull('category') or maybe where('category', '<>', '')


Make use of conditional clauses:

This should solve your problem

$data = $request->all();

$product =  Products::select('id', 'title)
->when(!empty($data['category']) , function ($query) use($data){
return $query->where('category',$data['category']);
->when (!empty($data['title']) , function ($query) use($data){
return $query->where('title',$data['title']);

return $product ;
Last updated 6 years ago.

You should use conditional clause. Here take a look at this piece of documentation.


Sign in to participate in this thread!

Full Stack Europe

Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.