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

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

0

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 ;
Last updated 6 years ago.
0

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

https://laravel.com/docs/5.4/queries#conditional-clauses

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.