PHPackages                             mpyw/laravel-local-class-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. mpyw/laravel-local-class-scope

ActiveLibrary[Database &amp; ORM](/categories/database)

mpyw/laravel-local-class-scope
==============================

A tiny macro that reuse a global scope class as a local scope

v2.2.0(1y ago)24102.6k—8.1%4[1 PRs](https://github.com/mpyw/laravel-local-class-scope/pulls)MITPHPPHP ^8.2CI passing

Since May 4Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/mpyw/laravel-local-class-scope)[ Packagist](https://packagist.org/packages/mpyw/laravel-local-class-scope)[ RSS](/packages/mpyw-laravel-local-class-scope/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (10)Used By (0)

Laravel Local Class Scope [![Build Status](https://github.com/mpyw/laravel-local-class-scope/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/laravel-local-class-scope/actions) [![Coverage Status](https://camo.githubusercontent.com/ac52f7055d2be33d2ad1daf10770f2eb132ef2d8962eae103c3b64fc4e1755a4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7079772f6c61726176656c2d6c6f63616c2d636c6173732d73636f70652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mpyw/laravel-local-class-scope?branch=master)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-local-class-scope--)

A tiny macro that reuse a global scope class as a local scope.

The idea is from: [\[Proposal\] Local query scopes as classes · Issue #636 · laravel/ideas](https://github.com/laravel/ideas/issues/636)

Requirements
------------

[](#requirements)

- PHP: `^8.2`
- Laravel: `^11.0 || ^12.0`

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Installing
----------

[](#installing)

```
composer require mpyw/laravel-local-class-scope
```

Usage
-----

[](#usage)

### Simple Scope

[](#simple-scope)

```
class ActiveScope implements Scope
{
    public function apply(Builder $query, Model $model): void
    {
        $query->where('active', true);
    }
}
```

```
User::scoped(ActiveScope::class)->get();
```

```
User::scoped(new ActiveScope())->get();
```

### Scope that takes arguments

[](#scope-that-takes-arguments)

```
class AgeScope implements Scope
{
    protected $parameters;

    public function __construct(...$parameters)
    {
        $this->parameters = $parameters;
    }

    public function apply(Builder $query, Model $model): void
    {
        $query->where('age', ...$this->parameters);
    }
}
```

```
User::scoped(AgeScope::class, '>', 18)->get();
```

```
User::scoped(new AgeScope('>', 18))->get();
```

### Combination

[](#combination)

```
User::scoped(ActiveScope::class)->scoped(AgeScope::class, '>', 18)->get();
```

### Re-define as a local method scope

[](#re-define-as-a-local-method-scope)

```
class User extends Model
{
    public function scopeActive(Builder $query): Builder
    {
        return $this->scoped(ActiveScope::class);
    }
}
```

### Share local method re-definition via trait

[](#share-local-method-re-definition-via-trait)

```
trait ScopesActive
{
    public function scopeActive(Builder $query): Builder
    {
        return $this->scoped(ActiveScope::class);
    }
}
```

```
class User extends Model
{
    use ScopesActive;
}
```

```
class Admin extends Model
{
    use ScopesActive;
}
```

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance60

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community11

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% 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 ~266 days

Recently: every ~402 days

Total

9

Last Release

440d ago

Major Versions

v1.0.2 → v2.0.02019-10-03

PHP version history (5 changes)v1.0.0PHP ^7.1

v2.0.1PHP ^7.1 || ^8.0

v2.1.0PHP ^7.3 || ^8.0

v2.1.2PHP ^8.0

v2.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1351893?v=4)[mpyw](/maintainers/mpyw)[@mpyw](https://github.com/mpyw)

---

Top Contributors

[![mpyw](https://avatars.githubusercontent.com/u/1351893?v=4)](https://github.com/mpyw "mpyw (25 commits)")[![hexium310](https://avatars.githubusercontent.com/u/10758173?v=4)](https://github.com/hexium310 "hexium310 (1 commits)")

---

Tags

eloquentlaravelmacrophplaraveldatabaseeloquentquerybuilderilluminatemacroscope

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mpyw-laravel-local-class-scope/health.svg)

```
[![Health](https://phpackages.com/badges/mpyw-laravel-local-class-scope/health.svg)](https://phpackages.com/packages/mpyw-laravel-local-class-scope)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)

PHPackages © 2026

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