Interview frequency: …
Short answer
A Local Scope is a helper method called manually to reuse query conditions, while a Global Scope is applied automatically to all queries for the model unless explicitly removed.
Explanation
A Local Scope starts with scope (such as scopeActive) and allows calls like User::active()->get(). A Global Scope, such as SoftDeletes, applies a condition consistently, for example, isolating the current tenant's data or excluding blocked accounts. Remove a Global Scope when needed with withoutGlobalScope().
Code example
// Local scope
public function scopeActive(Builder $query): void {
$query->where('status', 'active');
}
// Use: User::active()->get();Common mistakes
- Applying a complex Global Scope without appropriate indexes, slowing down every query on the table.