Laravel & Ecosystem (50 Qs)•Part 2: Eloquent ORM, Security & Queue Ecosystem (11 - 24)
What are Eloquent Scopes (Local vs Global Scopes)?
junior LevelCode ExampleSecurity & AuthData Structures
In Simple Words:
- Local Scope: Reusable query constraints prefixed with
scope:php// In User model: public function scopeActive($query) { return $query->where('status', 'active'); } // Usage: $activeUsers = User::active()->where('country', 'US')->get(); - Global Scope: Automatically applied to every query executed on the model (e.g. Soft Deletes uses a global scope:
WHERE deleted_at IS NULL).