Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Global Or Scope

Laravel Global Or Scope Laravel Package

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().

View on GitHub
Deep Wiki
Context7

A Laravel package to add possibility to use global scopes with an or operation in Eloquent Models.

Frequently asked questions about Laravel Global Or Scope
How do I apply multiple global scopes with OR logic in Laravel instead of the default AND?
Use the `GlobalOrScope` trait in your Eloquent model and call `addGlobalOrScopes([Scope1::class, Scope2::class])` in the `booting()` method. This groups the scopes with OR logic, like `WHERE (scope1 OR scope2)`.
Can I mix global OR scopes with existing global AND scopes in the same model?
Yes. The package works alongside Laravel’s native global scopes (AND logic). Just add both `addGlobalScope()` and `addGlobalOrScopes()` in your model’s `booting()` method—they’ll combine naturally.
How do I disable global OR scopes for a specific query in Laravel?
Use `withoutGlobalOrScopes()` on your query builder. For example: `Post::query()->withoutGlobalOrScopes()->get()`. This temporarily removes all OR-scoped conditions.
What Laravel and PHP versions does this package support?
The package requires **PHP 8.1+** and **Laravel 9+** (tested up to Laravel 12). If you’re on an older version, consider alternatives like manual `orWhere` chains or custom query scopes.
Will global OR scopes impact query performance or indexing?
OR conditions can complicate queries (e.g., `WHERE (A OR B) AND C`), potentially reducing index effectiveness. Test with `DB::enableQueryLog()` and ensure scoped columns are indexed. Avoid overusing OR in high-traffic queries.
Can I nest OR scopes (e.g., `(Scope1 OR Scope2) AND (Scope3 OR Scope4)`) in Laravel?
Yes, but explicitly. Use `OrScope` to group scopes manually, like `new OrScope([Scope1::class, Scope2::class])`. This gives you control over parenthesized logic, though it requires more boilerplate.
How do I test models using global OR scopes in PHPUnit?
Mock the `booting()` method or use `withoutGlobalOrScopes()` in tests to isolate scope behavior. For example: `$model->newQuery()->withoutGlobalOrScopes()->get()` ensures clean test queries.
Are there alternatives to this package for OR logic in Laravel?
Yes: (1) **Manual `orWhere`**: Less maintainable but flexible. (2) **Custom query scopes**: Define `scopeActiveOrArchived()` with `orWhere` logic. (3) **Database views**: Overkill for dynamic filtering. This package is the cleanest for reusable OR scopes.
How do I disable *specific* OR scopes instead of all of them?
The package currently disables *all* OR scopes with `withoutGlobalOrScopes()`. For granular control, refactor scopes into separate groups or use `OrScope` with conditional logic in your query.
Does this package work with Laravel’s `SoftDeletes` or other built-in global scopes?
Absolutely. Built-in scopes like `SoftDeletes` (AND logic) coexist seamlessly with OR scopes. Just ensure your `booting()` method includes both: `static::addGlobalScope(SoftDeletes::class); static::addGlobalOrScopes([...]);`
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata