How to do filter for products (laravel)
You can create a local scope. Something like:
public function scopeFilter($q)
{
if (request('price_from')) {
$q->where('price', '>', request('price_from'));
}
if (request('color')) {
$q->where('color', '>', request('color'));
}
return $q;
}
Then use it:
Product::filter()->paginate(20);