lacodix/laravel-global-or-scope
Add multiple Eloquent global scopes that are grouped and applied with OR logic instead of the default AND. Use a simple trait to register OR-scopes and optionally disable some or all of them per query with withoutGlobalOrScopes().
Architecture Fit
The laravel-global-or-scope package provides a declarative way to apply global query scopes or OR conditions across Eloquent models, aligning well with Laravel’s query builder patterns. Its focus on reusable, model-agnostic query logic fits seamlessly into Laravel’s architecture, particularly for applications requiring consistent filtering or conditional logic across multiple models (e.g., soft-deletes, tenant isolation, or multi-tenancy). The package abstracts complexity behind a clean facade, reducing boilerplate while maintaining readability.
Integration Feasibility Integration is straightforward for Laravel applications, especially those already leveraging Eloquent. The package requires minimal setup (service provider binding and model configuration) and integrates via method chaining, preserving Laravel’s fluent query syntax. For monolithic applications, adoption is low-risk; however, microservices or modular architectures may need to evaluate whether global scopes should be centralized or distributed.
Technical Risk
OR clauses).DB::enableQueryLog()) and unit tests for critical models.Key Questions
composer require).Stack Fit
Migration Path
GlobalScope traits) to identify redundancy.composer require lacodix/laravel-global-or-scope).config/app.php.use GlobalScope or applyGlobalScopes().php artisan tinker) or Laravel Debugbar.WHERE vs. OR behavior).Compatibility
Spatie\Activitylog). Resolve via priority ordering or namespace isolation.Sequencing
User or Post) to validate scope behavior.removeGlobalScopes()).Maintenance
composer update lacodix/laravel-global-or-scope).Support
GlobalScope::skip() to temporarily disable scopes during troubleshooting.Scaling
OR scopes can bloat queries. Monitor with:
unless() or only() to conditionally apply scopes.whereIn with cached IDs).Failure Modes
| Scenario | Impact | Mitigation |
|---|---|---|
| Scope conflicts | Incorrect query logic | Test scope interactions early. |
| Package update breaks | Query failures | Pin version in composer.json. |
| Overly broad scopes | Performance degradation | Audit scope selectivity. |
| Laravel version gap | Compatibility issues | Use Laravel’s version constraints. |
Ramp-Up
GlobalScope vs. LocalScope.How can I help you explore Laravel packages today?