mpyw/laravel-local-class-scope
Scope classes (e.g., ActiveScope, AgeScope), improving testability and maintainability compared to inline closures.scoped()) is additive.Scope classes be simpler than closures?User) and migrate one scope to a class (e.g., ActiveScope).scoped() macro alias for backward compatibility if needed.Scope interfaces.assertDatabaseHas).Scope classes may require adjustments in existing tests (e.g., __construct parameters).composer.json meets PHP/Laravel version requirements.composer require mpyw/laravel-local-class-scope.ActiveScope, PublishedScope).// Before
User::where(fn($q) => $q->where('active', true))->get();
// After
User::scoped(ActiveScope::class)->get();
app/Scopes/ directory).use Builder; use Model;).Scopes namespace or directory.apply() method, improving error diagnosis.Scope interface.where() vs. orWhere()).ScopeContract interface or trait to enforce consistency.Class 'NonExistentScope' not found if the class isn’t autoloaded.
App\Scopes\ActiveScope).WHERE active = true AND age > 30 AND active = false).
ActiveScope example).app/Scopes/ directory as templates.How can I help you explore Laravel packages today?