Query Scopes: Reusable Filters in Models
Create reusable query logic using local scopes in Eloquent models.
Laura Adams
December 21, 2025
0.0k0
Query scopes allow you to define common filters directly in your models. ## Define a scope ```php public function scopePublished($query) { return $query->where('status', 'published'); } ``` ## Use it ```php $posts = Post::published()->latest()->get(); ``` Scopes keep controllers clean and logic centralized. In the next tutorial, we will implement soft deletes.
#Laravel#Eloquent#Intermediate