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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners