PHPackages                             sofa/eloquent-scopes - 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. sofa/eloquent-scopes

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

sofa/eloquent-scopes
====================

Handy scopes for the eloquent (Laravel) query builder.

v1.0.3(10y ago)83161MITPHPPHP &gt;=5.4

Since Sep 16Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jarektkaczyk/eloquent-scopes)[ Packagist](https://packagist.org/packages/sofa/eloquent-scopes)[ RSS](/packages/sofa-eloquent-scopes/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Sofa/Eloquent-Scopes
====================

[](#sofaeloquent-scopes)

Handy scopes for Eloquent (Laravel) query builder.

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

[](#installation)

Package requires **PHP 5.4+** and works with **Laravel 5/5.1**.

1. Require the package in your `composer.json`:

    ```
        "require": {
            ...
            "sofa/eloquent-scopes": "~1.0",
        },

    ```
2. Add trait to your class, eg. `use \Sofa\EloquentScopes\PeriodScopes`;

Usage example
-------------

[](#usage-example)

### `PeriodScopes` - provides methods for easy fetching records in given range, relative to NOW.

[](#periodscopes---provides-methods-for-easy-fetching-records-in-given-range-relative-to-now)

```
class Subscription extends Model
{
    use PeriodScopes;

    // optionally you may provide the column to be filtered
    //   By default self::CREATED_AT -> 'created_at' will be used
    const PERIOD_COLUMN = 'expires_at';
}

class Subscription extends Model
{
    use PeriodScopes;
}
```

```
// Given it's September 11th, 2015

// count users created in August
User::lastMonth()->count();

// get users created on September 10th
User::yesterday()->get();

// count users who logged-in in 2014 & 2015
User::periods('year', 1, 'last_login', true)->count();

// count users created in 2014 & 2015
User::periods('year', -1, null, true)->count();
// or
User::periods('year', -1, true)->count();

// Get subscriptions expiring in October
User::nextMonth()->get();

// Get subscriptions expired in past 7 days
User::periods('day', -7)->get();

// Get subscriptions expiring in next 30 days
User::periods('day', 30)->get();

//
// Obviously these are query extensions, so you can chain them however you like
//
User::query()->tomorrow()->get();
User::where(...)->tomorrow()->get();
(new User)->tomorrow()->get();
```

Roadmap
-------

[](#roadmap)

TBA

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~0 days

Total

4

Last Release

3943d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/34d383bf50d6c73fc747d89a5efacd41ccecc9695aec04148a7c04fc00ef26e7?d=identicon)[jarektkaczyk](/maintainers/jarektkaczyk)

---

Top Contributors

[![jarektkaczyk](https://avatars.githubusercontent.com/u/6928818?v=4)](https://github.com/jarektkaczyk "jarektkaczyk (6 commits)")

---

Tags

laraveldatabaseeloquentscopes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sofa-eloquent-scopes/health.svg)

```
[![Health](https://phpackages.com/badges/sofa-eloquent-scopes/health.svg)](https://phpackages.com/packages/sofa-eloquent-scopes)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

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

592456.3k2](/packages/spiritix-lada-cache)[lapaliv/laravel-bulk-upsert

1533.3k](/packages/lapaliv-laravel-bulk-upsert)[guidocella/eloquent-populator

Guess attributes for Eloquent model factories

7762.7k2](/packages/guidocella-eloquent-populator)[mvanduijker/laravel-model-exists-rule

Validation rule to check if a model exists

22215.3k2](/packages/mvanduijker-laravel-model-exists-rule)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3262.5k4](/packages/toponepercent-baum)

PHPackages © 2026

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