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: https://laravel.com/docs/5.4/queries#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']);
})
->get()
return $product ;
You should use conditional clause. Here take a look at this piece of documentation.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community