There might be some times when you have 10+ scopes in your model which can make your model cluttered ! Well today i have that solution for you along with a bonus tip ! Imagine we have a model like this: where('quantity','!=', 0); } public function scopeSortFilterBy($query,$sortBy = "") { switch ($sortBy) { case 'featured': return $query->where('featured','=', -1); break; case 'low': return $query->orderBy('sale_price', 'asc'); break; case 'heigh': return $query->orderBy('sale_price', 'desc'); break; default: return $query; break; } } public function scopeFilterAttributes($query,$checkboxValues) { if($checkboxValues !== NULL){ return $query->whereHas('attributeValues', function ($query) use($checkboxValues){ $query->whereIn('value',$checkboxValues); }); } return $query; } public function scopeSearchProducts($query,$search = "") { if($search !== NULL){ $searchTerm = '%'.

''); } return $query; } public function scopeSubcategoriesIds($query,$arrayOfSubcategoryIds = "") { if($arrayOfSubcategoryIds !== NULL){ return $query->orWhereIn('category_id', $arrayOfSubcategoryIds); } return $query; }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners