Performance: Query scopes
MEDIUM IMPACT
Query scopes affect database query performance and server response time by reusing query logic efficiently.
class User extends Model { public function scopeActiveAdmin($query) { return $query->where('active', 1)->where('role', 'admin'); } } User::activeAdmin()->get();
User::where('active', 1)->where('role', 'admin')->get(); // Repeated in many places without reuse
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated query conditions without scopes | N/A | N/A | N/A | [X] Bad |
| Using query scopes for reusable conditions | N/A | N/A | N/A | [OK] Good |