PHPackages                             joelbutcher/eloquent-repositories - 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. joelbutcher/eloquent-repositories

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

joelbutcher/eloquent-repositories
=================================

A repository pattern implementation for Laravel Eloquent models.

v1.0.0(3y ago)35MITPHPPHP ^8.0.2

Since Sep 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/joelbutcher/eloquent-repositories)[ Packagist](https://packagist.org/packages/joelbutcher/eloquent-repositories)[ Fund](https://paypal.me/joelbutcher)[ GitHub Sponsors](https://github.com/joelbutcher)[ RSS](/packages/joelbutcher-eloquent-repositories/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (3)Used By (0)

Eloquent Repositories
=====================

[](#eloquent-repositories)

[ ![Build Status](https://github.com/joelbutcher/eloquent-repositories/workflows/tests/badge.svg)](https://github.com/joelbutcher/eloquent-repositories/actions)[ ![Total Downloads](https://camo.githubusercontent.com/de2296323fc80aab8feefce629faedf0443afc3f3a959cb5ed86982f66db02d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f656c627574636865722f656c6f7175656e742d7265706f7369746f72696573)](https://packagist.org/packages/joelbutcher/eloquent-repositories)[ ![Latest Stable Version](https://camo.githubusercontent.com/d439b60311afc07d7ca43f2f402a90e4680ae5cc86ab5d125d22ffa8e38aa53d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f656c627574636865722f656c6f7175656e742d7265706f7369746f72696573)](https://packagist.org/packages/joelbutcher/eloquent-repositories)[ ![License](https://camo.githubusercontent.com/f7127ffaeed4e18592ac82925025c21efde79a8e4daa2958bbc1432c81e34422/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6f656c627574636865722f656c6f7175656e742d7265706f7369746f72696573)](https://packagist.org/packages/joelbutcher/eloquent-repositories)Eloquent Repositories is a light-weight solution to add the repository pattern (built on top of Eloquent) to your Laravel project.

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

[](#requirements)

This package requires Laravel 8 or higher and PHP 7.4 or higher.

Getting Started
---------------

[](#getting-started)

Add this package to your project using Composer:

```
composer require joelbutcher/eloquent-repositories
```

Creating a repository
---------------------

[](#creating-a-repository)

The quickest way to create a repository is to use the `make:repository` command. This command accepts the name of the repository you with to create:

```
php artisan make:repository PostRepository
```

This command will create a new repository in the `app/Repositories` directory in your Laravel application.

You may also optionally append the `--model=` option to specify the repository should be created for the given model. (The model needs to have been created prior to running this command.)

```
php artisan make:repository PostRepository --model=Post
php artisan make:repository PostRepository -m Post
```

You may also use the `test` or `pest` options to create PHPUnit or Pest test files for the repository.

### Manual Creation

[](#manual-creation)

Of course, you may also create a repository manually

```
use App\Models\Post;
use JoelButcher\EloquentRepositories\Repository;
use Illuminate\Database\Eloquent\Model;

class PostRepository extends Repository
{
    protected static function model(): string
    {
        return Post::class;
    }

    public function firstForSlug(string $slug): ?Model
    {
        return $this->where('slug', '=', $slug)->first();
    }
}
```

Using a repository
------------------

[](#using-a-repository)

To use a repository, you may "inject" it into any class that requires it:

```
class UpdatePost
{
    public function __construct(
        private readonly PostValidator $validator,
        private readonly PostRepository $repository
    ) {
    }

    public function update(array $data): void
    {
        $this->validator->validate($data);

        $this->repository->upsert($data, ['slug'], ['slug']);
    }
}
```

Interface Binding
-----------------

[](#interface-binding)

You may decide to bind a repository to an interface, you may do so by implementing this interface in your repository and then binding the concrete repository implementation to the service container:

```
class UserRepository extends Repository implements UserRepositoryContract
{
    //
}

class MyServiceProvider extends ServiceProvider
{
    public function boot():
    {
        $this->app->bind(UserRepositoryContract::class, UserRepository::::class)
    }
}
```

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

[](#contributing)

Thank you for considering contributing to Eloquent Repositories! You can read the contribution guide [here](.github/CONTRIBUTING.md).

Code of Conduct
---------------

[](#code-of-conduct)

In order to ensure that the community is welcoming to all, please review and abide by the [Code of Conduct](.github/CODE_OF_CONDUCT.md).

License
-------

[](#license)

This project is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

2

Last Release

1337d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb6903ee363d9201681e47a2dcbe12148b7d299dd9e37229cad774ecd923fd6e?d=identicon)[joelbutcher](/maintainers/joelbutcher)

---

Tags

laraveleloquentrepositories

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/joelbutcher-eloquent-repositories/health.svg)

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[baril/bonsai

An implementation of the Closure Tables pattern for Eloquent.

3593.5k](/packages/baril-bonsai)[toponepercent/baum

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

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

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