Eloquent Scopes are one of Laravel’s most elegant features for organizing database queries and keeping your codebase clean.
Instead of repeating query conditions across controllers and services, scopes allow you to define reusable constraints directly inside the model.
## What Are Eloquent Scopes?
Eloquent Scopes are reusable query methods defined inside your Eloquent models.
Laravel supports two types:
- Local Scopes
- Global Scopes
## Local Scopes
Local scopes are perfect for repeated query conditions.
### Example
```php
class Post extends Model
{
public function scopePublished($query)
{
return $query->where('published', true);
}
public function scopeLatestPublished($query)
{
return $query->published()
->orderByDesc('published_at');
}
}
Usage
Post::published()->get();
Post::latestPublished()->paginate(10);
The result:
Cleaner queries
Better readability
Less duplication
Why Scopes Matter
Without scopes, query logic often spreads across:
Controllers
Services
Repositories
Scopes centralize query logic inside the model, improving:
Maintainability
Readability
Long-term scalability
Global Scopes
Global scopes apply constraints automatically to all queries.
Common Use Cases
Soft deletes
Multi-tenant filtering
Active-only records
class ActiveScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$builder->where('is_active', true);
}
}
Best Practices
Use clear and meaningful scope names
Keep scopes focused on query logic
Combine scopes for flexible queries
Prefer scopes over duplicated conditions
Final Thoughts
Eloquent Scopes don’t just shorten queries —
they significantly improve the structure of your Laravel applications.
A must-use feature for every Laravel developer 💜
Laravel
Tutorial
Laravel Eloquent Scopes: Cleaner & Reusable Queries
Mohamed Shahin
Jan 09, 2026
•
2 min read
Key Takeaways
- Laravel Eloquent Scopes help you write cleaner, reusable, and expressive database queries by encapsulating query logic directly inside your models.
Update
Added a complete explanation of Eloquent Scopes with real-world examples.
Mohamed Shahin
Software Engineer
You might also like
Laravel
2 min read
Laravel Database Transactions: Keeping Your Data Safe
Laravel Database Transactions ensure data consistency by executing multiple database operations as a single atomic process.
Jan 09, 2026
Read
Laravel
1 min read
Laravel Octane: Supercharging Laravel Performance
Laravel Octane dramatically boosts Laravel performance by keeping the application in memory using Swoole or RoadRunner.
Jan 09, 2026
Read
Laravel
2 min read
Laravel DTOs Explained: Writing Cleaner and More Predictable Code
Learn how Data Transfer Objects (DTOs) can help you write cleaner, safer, and more predictable Laravel applications by structuring data flow between layers.
Jan 09, 2026
Read