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

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

phucnguyenvn/laravel-eloquent-repository
========================================

Repository pattern for Eloquent ORM

1.0.1(7y ago)17BSD-3-ClausePHPPHP &gt;=5.4.0

Since Jan 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/phucnguyenvn/laravel-eloquent-repository)[ Packagist](https://packagist.org/packages/phucnguyenvn/laravel-eloquent-repository)[ RSS](/packages/phucnguyenvn-laravel-eloquent-repository/feed)WikiDiscussions master Synced 3w ago

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

Eloquent Repository
===================

[](#eloquent-repository)

Package to assist the implementation of the Repository Pattern using Eloquent ORM.

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

[](#installation)

Installing via Composer

```
composer require phucnguyenvn/laravel-eloquent-repository
```

To configure the package options, declare the Service Provider in the `config/app.php` file.

```
'providers' => [
    ...
    phucnguyenvn\EloquentRepository\Providers\RepositoryServiceProvider::class,
],
```

> If you are using version 5.5 or higher of Laravel, the Service Provider is automatically recognized by Package Discover.

### Usage

[](#usage)

To get started you need to create your repository class and extend the `EloquentRepository` available in the package. You also have to set the *Model* that will be used to perform the queries.

Example:

```
namespace App\Repositories;

use App\Models\User;
use phucnguyenvn\EloquentRepository\Repositories\EloquentRepository;

class UserRepository extends EloquentRepository
{
    /**
     * Repository constructor.
     */
    public function __construct(User $user){
        parent::__construct($user);
    }
}
```

Now it is possible to perform queries in the same way as it is used in Eloquent.

```
namespace App\Repositories;

use App\Models\User;
use phucnguyenvn\EloquentRepository\Repositories\EloquentRepository;

class UserRepository extends EloquentRepository
{
    /**
     * Repository constructor.
     */
    public function __construct(User $user){
        parent::__construct($user);
    }

    public function getAllUser(){
        return $this->all();
    }

    public function getByName($name) {
        return $this->where("name", $name)->get();
    }

    // You can create methods with partial queries
    public function filterByProfile($profile) {
        return $this->where("profile", $profile);
    }

    // Them you can use the partial queries into your repositories
    public function getAdmins() {
        return $this->filterByProfile("admin")->get();
    }
    public function getEditors() {
        return $this->filterByProfile("editor")->get();
    }

    // You can also use Eager Loading in queries
    public function getWithPosts() {
        return $this->with("posts")->get();
    }
}
```

To use the class, just inject them into the controllers.

```
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Repositories\UserRepository;

class UserController extends Controller
{
    protected function index(UserRepository $repository) {
        return $repository->getAdmins();
    }
}
```

The injection can also be done in the constructor to use the repository in all methods.

```
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Repositories\UserRepository;
class UserController extends Controller
{
    private $userRepository;
	public function __construct()(UserRepository $userRepository) {
        $this->userRepository = $userRepository;
    }

    public function index() {
        return $this->userRepository->getAllUsers();
    }

}
```

> The Eloquent/QueryBuilder methods are encapsulated as protected and are available just into the repository class. Declare your own public data access methods within the repository to access them through the controller.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity57

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

2713d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/26a38fa89a54d7c6fafe110ce06fe84c67f4ec06c24b6480b4564c982e38f830?d=identicon)[phucnguyenvn](/maintainers/phucnguyenvn)

---

Tags

laraveleloquentrepository

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[prettus/l5-repository

Laravel 8|9|10|11|12|13 - Repositories to the database layer

4.2k11.2M153](/packages/prettus-l5-repository)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[watson/validating

Eloquent model validating trait.

9733.4M53](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k322.4k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567714.4k4](/packages/cviebrock-eloquent-taggable)

PHPackages © 2026

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