PHPackages                             lacodix/laravel-global-or-scope - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. lacodix/laravel-global-or-scope

ActiveLaravel-package[Database &amp; ORM](/categories/database)

lacodix/laravel-global-or-scope
===============================

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

v1.2.0(10mo ago)5688↑592.3%1MITPHPPHP ^8.1CI passing

Since Feb 19Pushed 10mo ago2 watchersCompare

[ Source](https://github.com/lacodix/laravel-global-or-scope)[ Packagist](https://packagist.org/packages/lacodix/laravel-global-or-scope)[ Docs](https://github.com/lacodix/laravel-global-or-scope)[ GitHub Sponsors](https://github.com/lacodix)[ RSS](/packages/lacodix-laravel-global-or-scope/feed)WikiDiscussions master Synced today

READMEChangelog (8)Dependencies (14)Versions (13)Used By (0)

laravel-global-or-scope
=======================

[](#laravel-global-or-scope)

[![Latest Version on Packagist](https://camo.githubusercontent.com/db73c75ce728a1d7572ee11ff8672eb4225a5b84c5ebeefe450d6af6a4c0b4d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61636f6469782f6c61726176656c2d676c6f62616c2d6f722d73636f70652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lacodix/laravel-global-or-scope)[![GitHub Tests Action Status](https://camo.githubusercontent.com/bfdc8ff37a57d8e10e8ab3c597d4e7f8fc59cd9ca8b4a55b12fea3c3edd786f1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c61636f6469782f6c61726176656c2d676c6f62616c2d6f722d73636f70652f746573742e79616d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/lacodix/laravel-global-or-scope/actions?query=workflow%3Atest+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/33af45a534c9ff1740220615e4c7bebbe7e86559fda33f5736c36cc0baf35f7d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c61636f6469782f6c61726176656c2d676c6f62616c2d6f722d73636f70652f7374796c652e79616d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/lacodix/laravel-global-or-scope/actions?query=workflow%3Astyle+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/0f661d4078037ad2d1a6c0be71f8cfc0ca85c5ba4bbcf034fe28b8cf3ff5852e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61636f6469782f6c61726176656c2d676c6f62616c2d6f722d73636f70652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lacodix/laravel-global-or-scope)

This package allows you to add global scopes to models combined with an or condition. It contains additional functionality to disable some or all or-scopes on the fly.

Documentation
-------------

[](#documentation)

You can find the entire documentation for this package on [our documentation site](https://www.lacodix.de/docs/laravel-global-or-scope)

Installation
------------

[](#installation)

```
composer require lacodix/laravel-global-or-scope
```

Basic Usage
-----------

[](#basic-usage)

Just add the trait to your eloquent model and then you can use the addGlobalOrScopes method when booting.

```
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Lacodix\LaravelGlobalOrScope\Traits\GlobalOrScope;

class Post extends Model
{
    use GlobalOrScope;

    public static function booting(): void
    {
        static::addGlobalOrScopes([Scope1::class, Scope2::class]);
    }
}

class Scope1 implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        return $builder->whereNull('col1')->where('col2', 1);
    }
}

class Scope2 implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        return $builder->where('col3', 2);
    }
}
...
Post::query()->where('user_id', 1000)->get();
```

This results in running the following SQL Query

```
select * from "posts" where "user_id" = 1000 and (("col1" is null and "col2" = 1) or ("col3" = 2))
```

For temporary disabling you can use

```
Post::query()->withoutGlobalOrScopes()->where('user_id', 1000)->get();
```

what results in a simple

```
select * from "posts" where "user_id" = 1000
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.

```
composer rector:test
composer insights
composer csfixer:test
composer phpstan:test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [lacodix](https://github.com/lacodix)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 87% of packages

Maintenance54

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~111 days

Total

8

Last Release

316d ago

Major Versions

v0.2.0 → v1.0.02024-02-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/123ffce0596acef2904868164413bca95eeeaa4e2ba557b3620f11fce22cfbb7?d=identicon)[lacodix](/maintainers/lacodix)

---

Top Contributors

[![renky](https://avatars.githubusercontent.com/u/6528960?v=4)](https://github.com/renky "renky (12 commits)")

---

Tags

eloquentlaravellaravel-packagequeryscopeslaravelmodeleloquentscopesgloballacodix

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lacodix-laravel-global-or-scope/health.svg)

```
[![Health](https://phpackages.com/badges/lacodix-laravel-global-or-scope/health.svg)](https://phpackages.com/packages/lacodix-laravel-global-or-scope)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4832.7M8](/packages/dyrynda-laravel-model-uuid)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17648.2k](/packages/lacodix-laravel-model-filter)[elipzis/laravel-cacheable-model

Automatic query-based model cache for your Laravel app

15544.1k](/packages/elipzis-laravel-cacheable-model)[kiwilan/typescriptable-laravel

PHP package for Laravel to type Eloquent models, routes, Spatie Settings with autogenerated TypeScript. If you want to use some helpers with Inertia, you can install associated NPM package.

4019.6k](/packages/kiwilan-typescriptable-laravel)[indracollective/laravel-revisor

Draft, publish and revise Laravel Eloquent Models

196.8k](/packages/indracollective-laravel-revisor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
