PHPackages                             doctorbeat/eloquent-repository - 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. doctorbeat/eloquent-repository

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

doctorbeat/eloquent-repository
==============================

A repository for eloquent models. Using this makes the model appear to have a sigle responsibility

v1.0.2(10y ago)034MITPHPPHP &gt;=5.3.2

Since Mar 26Pushed 10y ago1 watchersCompare

[ Source](https://github.com/doctor-beat/eloquent-repository)[ Packagist](https://packagist.org/packages/doctorbeat/eloquent-repository)[ RSS](/packages/doctorbeat-eloquent-repository/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

eloquent-repository
===================

[](#eloquent-repository)

A repository for eloquent models. Using this makes the model appear to have a single responsibility and thus makes them unit-testable in isolation

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

[](#installation)

Via composer:

```
require: "doctorbeat/eloquent-repository": "*"

```

Why a respository?
------------------

[](#why-a-respository)

Eloquent is great for its simplicity but this simplicity makes that Eloquent models breaks the 'single responsibility" principle. An Eloquent model is both a entity (property bag) AND dealing with database interaction (select, insert, update, delete). And this makes that you can not mock your models in isolation. You need the entity functionality but want to mock the database interaction.

This problem is further shown in the fact that Eloquent models use static functions like find(), all() and where().

In comes the Eloquent Repository which make you able to use a model as an entity/property bag moves all database interaction methods to the repository. The repository comes with an interface which can be mocked.

Methods and api
---------------

[](#methods-and-api)

These methods are available on the repository and have an api equal to the corresponding Eloquent method:

- save
- delete
- push
- touch
- all
- find
- where\*
- all other static methods

Relations
---------

[](#relations)

To get relations from the repository use these methods:

```
   [Model:]           [Repository:]                             [result]
-  $model->parent     $repo->getAttribute($model, 'parent');    the parent model
-  $model->children   $repo->getAttribute($model, 'children');  the child models as a collection
-  $model->children() $repo->children($model);                  the child models as a relation
-  $model->children()->save($child)
                      $repo->children($model, $child);          add the child to the children of the model
-  $model->children()->saveMany($list)
                      $repo->children($model, $list);           add an array of new children to the children of the model
```

These examples assume that you have defined parent and children as relations on the model!

Usage
-----

[](#usage)

```
        $repo = new EloquentRepository('App\\Person');

        $ent = new Person();
        $ent->name = 'xyz';
        $repo->save($ent);
        $repo->delete($ent);

        $all = $repo->all();
        $person4 = $repo->find(4);
        $personXyz = $repo->whereName('xyz')->get();
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

3706d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30593dfc19d795e456653edaced20abb4313a518b1560286e6adba1e46eebab0?d=identicon)[doctor-beat](/maintainers/doctor-beat)

---

Top Contributors

[![doctor-beat](https://avatars.githubusercontent.com/u/11628099?v=4)](https://github.com/doctor-beat "doctor-beat (4 commits)")

---

Tags

eloquentrepository

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/doctorbeat-eloquent-repository/health.svg)

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

###  Alternatives

[prettus/l5-repository

Laravel 5|6|7|8|9|10|11|12 - Repositories to the database layer

4.2k10.8M145](/packages/prettus-l5-repository)[torann/laravel-repository

Base repository implementation for Laravel

88497.8k2](/packages/torann-laravel-repository)[czim/laravel-repository

Repository for Laravel (inspired by and indebted to Bosnadev/Repositories)

54110.0k4](/packages/czim-laravel-repository)[orkhanahmadov/eloquent-repository

Eloquent Repository for Laravel

2764.5k](/packages/orkhanahmadov-eloquent-repository)[adobrovolsky97/laravel-repository-service-pattern

Laravel 5|6|7|8|9|10 - Repository - Service Pattern

275.4k](/packages/adobrovolsky97-laravel-repository-service-pattern)[giordanolima/eloquent-repository

Repository pattern for Eloquent ORM with a powerfull cache for database queries.

301.5k](/packages/giordanolima-eloquent-repository)

PHPackages © 2026

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