PHPackages                             drh2so4/modelscope - 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. drh2so4/modelscope

ActiveLibrary

drh2so4/modelscope
==================

This is the simple package that allows you to utilize different laravel model scopes dealing with laravel query builders.

15PHPCI failing

Since May 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/pratiksh404/ModelScope)[ Packagist](https://packagist.org/packages/drh2so4/modelscope)[ RSS](/packages/drh2so4-modelscope/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Model Scopes
============

[](#model-scopes)

[![N|Solid](https://camo.githubusercontent.com/43f64fc6ca9e6dfcc60727cdda70606d53be52c95b70c9ce5137f9837aa1dcbe/68747470733a2f2f73636f6e74656e742e666b746d382d312e666e612e666263646e2e6e65742f762f74312e302d302f70363430783634302f36303130303637385f3635383133343237373936393539385f313233313430373436363339313031313332385f6f2e6a70673f5f6e635f6361743d313038265f6e635f7369643d383561353737265f6e635f6f68633d546d763133365f4b42774141582d714b6a444e265f6e635f68743d73636f6e74656e742e666b746d382d312e666e61265f6e635f74703d36266f683d6565346435613161323230623339363062663662666463666533373639653335266f653d3545434530433035)](https://www.facebook.com/doctypenepal)

This packages provides helpful query builder scopes. This package provide global scopes for every model by making making usage of trait where scopes is defined.

- Latest Data Retrive
- Week Data Retrive
- Year Data Retrive
- Month Data Retrive
- Between Date Data Retrive
- Not Between Date Data Retrive
- Order Ascending
- Order Descending
- Multiple Where Filtering
- Multiple orWhere Filtering

### Installation

[](#installation)

Run Composer Require Command

```
$ composer require drh2so4/modelscope
```

Use Namespace

```
use drh2so4\ModelScope\ModelScopes;
```

then.. Use Trait

```
use ModelScopes
```

Overall Structure

```
=',$date);
    }
```

### Usage

[](#usage-3)

```
$data = User::weekData()->get();
```

Retives week created data.

scopeWeekDataLimit($limit)
--------------------------

[](#scopeweekdatalimitlimit)

```
    public function scopeWeekDataLimit($query,$limit = 5){
        $date = Carbon::today()->subDays(7);
    $query->whereDate('updated_at','>=',$date)->take($limit);
    }
```

### Usage

[](#usage-4)

```
$data = User::weekDataLimit(8)->get();
```

Retives week $limit number of data if parameter is left empty retives 5(default parameter value) data

scopeMonthData()
----------------

[](#scopemonthdata)

```
    public function scopeMonthData($query){
        $date = Carbon::today()->subMonth();
        $query->whereDate('updated_at','>=',$date);
    }
```

### Usage

[](#usage-5)

```
$data = User::monthData()->get();
```

Retives month created data.

scopeMonthDataLimit($limit)
---------------------------

[](#scopemonthdatalimitlimit)

```
    public function scopeMonthDataLimit($query,$limit = 5){
        $date = Carbon::today()->subMonth();
        $query->whereDate('updated_at','>=',$date)->take($limit);
    }
```

### Usage

[](#usage-6)

```
$data = User::mothDataLimit(8)->get();
```

Retives month $limit number of data if parameter is left empty retives 5(default parameter value) data

scopeYearData()
---------------

[](#scopeyeardata)

```
    public function scopeYearData($query){
        $date = Carbon::today()->subYear();
        $query->whereDate('updated_at',$date);
    }
```

### Usage

[](#usage-7)

```
$data = User::yearData()->get();
```

Retives month created data.

scopeYearDataLimit($limit)
--------------------------

[](#scopeyeardatalimitlimit)

```
    public function scopeYearDataLimit($query,$limit = 5){
        $date = Carbon::today()->subYear();
        return $query->whereDate('updated_at','>=',$date)->take($limit);
    }
```

### Usage

[](#usage-8)

```
$data = User::yearDataLimit(8)->get();
```

Retives year $limit number of data if parameter is left empty retives 5(default parameter value) data

scopeTodayData()
----------------

[](#scopetodaydata-1)

```
    public function scopeTodayData($query){
        $date = Carbon::today();
        $query->whereDate('updated_at',$date);
    }
```

### Usage

[](#usage-9)

```
$data = User::todayData()->get();
```

Retives data created today.

scopeTillNowFrom($date)
-----------------------

[](#scopetillnowfromdate)

```
    public function scopeTillNowFrom($query,$date){
        $this->date_validate($date);
        $from = Carbon::createFromFormat('l jS \\of F Y',trim($date));
        return $query->whereDate('updated_at','>=',$from);
    }
```

### Usage

[](#usage-10)

```
$data = User::tillNowFrom('Thursday 25th of December 1975')->get();
```

Expects parameter as date in format 'l jS \\of F Y'. Retrives all data created from $date till now.

scopeDataBetween($from,$to)
---------------------------

[](#scopedatabetweenfromto)

```
    public function scopeDataBetween($query,$from_date,$to_date){
        $this->dates_validate($from_date,$to_date);
        $from = Carbon::createFromFormat('l jS \\of F Y',trim($from_date));
        $to = Carbon::createFromFormat('l jS \\of F Y',trim($to_date));
        return $query->whereBetween('updated_at',[$from,$to]);
    }

```

### Usage

[](#usage-11)

```
$data = User::dataBetween('Thursday 25th of December 1975',''Saturday 27th of December 1975')->get();
```

Expects parameter as date $from and $to in format 'l jS \\of F Y'. Retrives all data created $from and $to.

scopeDataNotBetween($from,$to)
------------------------------

[](#scopedatanotbetweenfromto)

```
    public function scopeDataNotBetween($query,$from_date,$to_date){
        $this->dates_validate($from_date,$to_date);
        $from = Carbon::createFromFormat('l jS \\of F Y',trim($from_date));
        $to = Carbon::createFromFormat('l jS \\of F Y',trim($to_date));
        return $query->whereNotBetween('updated_at',[$from,$to]);
    }
```

### Usage

[](#usage-12)

```
$data = User::dataNotBetween('Thursday 25th of December 1975',''Saturday 27th of December 1975')->get();
```

Expects parameter as date $from and $to in format 'l jS \\of F Y'. Doesn't retrives data created $from and $to.

scopeWhereFilter($array)
------------------------

[](#scopewherefilterarray)

```
    public function scopeWhereFilter($query, array $filterData = [])
    {
        foreach ($filterData as $key => $value) {

            if (is_null($value) || $value === '') continue;

            $scopeName = ucfirst(str::of($key)->camel());

            if (method_exists($this, 'scope' . $scopeName)) {
                $query->$scopeName($value);
            } else if (is_array($value)) {
                $query->whereIn($key, $value);
            } else {
                $query->where($key, $value);
            }
        }
    }
```

### Usage

[](#usage-13)

```
$data = User::whereFilter(['id' => '2'])->get();
```

Expect associative array where key is column name and value is column value. Retrives all the where condition mention. Above usage equals to User::where('id',2)-&gt;get()

### Also Supports multiple where condition !

[](#also-supports-multiple-where-condition-)

### Usage

[](#usage-14)

```
$data = User::whereFilter(['id' => '2','name' => 'Cat'])->get();
```

Retives data with id = 2 and name = cat

scopeorWhereFilter($array)
--------------------------

[](#scopeorwherefilterarray)

```
    public function scopeorWhereFilter($query, array $filterData = [])
    {
        foreach ($filterData as $key => $value) {

            if (is_null($value) || $value === '') continue;

            $scopeName = ucfirst(str::of($key)->camel());

            if (method_exists($this, 'scope' . $scopeName)) {
                $query->$scopeName($value);
            } else if (is_array($value)) {
                $query->orWhere($key, $value);
            } else {
                $query->where($key, $value);
            }
        }
    }
```

### Usage

[](#usage-15)

```
$data = User::orWhereFilter(['id' => '2'])->get();
```

Expect associative array where key is column name and value is column value. Retrives all the where condition mention. Above usage equals to User::orWhere('id',2)-&gt;get()

### Also Supports multiple orWhere condition !

[](#also-supports-multiple-orwhere-condition-)

### Usage

[](#usage-16)

```
$data = User::orWhereFilter(['id' => '2','name' => 'Cat'])->get();
```

Retives data with id = 2 or name = cat

### Todos

[](#todos)

Exceptions. More Scopes. Some Testing

License
-------

[](#license)

MIT

**DOCTYPE NEPAL ||DR.H2SO4**

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/001849cfcd496d28474179bde8e510e82ea2ff8b32291d2ac8fc905a754512e0?d=identicon)[pratiksh404](/maintainers/pratiksh404)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/drh2so4-modelscope/health.svg)

```
[![Health](https://phpackages.com/badges/drh2so4-modelscope/health.svg)](https://phpackages.com/packages/drh2so4-modelscope)
```

PHPackages © 2026

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