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

ActiveLibrary

ra3oul/eloquent-abstract-repository
===================================

laravel eloquent abstract repository to implement repository pattern in easy way

1.0(9y ago)151741MITPHP

Since Jun 15Pushed 9y ago2 watchersCompare

[ Source](https://github.com/ra3oul/laravel-eloquent-abstract-repository)[ Packagist](https://packagist.org/packages/ra3oul/eloquent-abstract-repository)[ RSS](/packages/ra3oul-eloquent-abstract-repository/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel 5 Eloquent Abstract repository
======================================

[](#laravel-5-eloquent-abstract-repository)

using repository pattern in laravel with a great base repository

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)

    - [Composer](#composer)
    - [Service Provider](#laravel)
- [Methods](#methods)

    - [RepositoryInterface](#prettusrepositorycontractsrepositoryinterface)
- [Usage](#usage)

    - [Create a Model](#create-a-model)
    - [Create a Repository](#create-a-repository)
    - [Create service Provider](#create-service-provider)
    - [Use methods](#use-methods)

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

[](#installation)

### Composer

[](#composer)

Execute the following command to get the latest version of the package:

```
composer require ra3oul/eloquent-abstract-repository -dev

```

### Laravel

[](#laravel)

In your `config/app.php` add `ra3oul\EloquentAbstractRepository\EloquentAbstractRepositoryServiceProvider::class` to the end of the `providers` array:

```
'providers' => [
    ...

    ra3oul\EloquentAbstractRepository\EloquentAbstractRepositoryServiceProvider::class,
],
```

Methods
-------

[](#methods)

### ra3oul\\EloquentAbstractRepository\\repository\\RepositoryInterface

[](#ra3ouleloquentabstractrepositoryrepositoryrepositoryinterface)

- create($columns = array('\*'))
- findOneById($id )
- findOneBy($key , $value )
- findManyBy($key,$value\])
- findManyByIds($ids = array())
- findAll()
- findManyByCredentials($credentials = array())
- paginateBy($key, $value, $perPage = 10)
- paginate($perPage = 10)
- paginateByCredentials(array $credentials, $perPage = 10)
- updateOneById($id, array $data = \[\])
- updateOneBy($key, $value, array $data = \[\])
- updateOneByCredentials(array $credentials, array $data = \[\]');
- updateManyBy($key, $value, array $data = \[\]);
- updateManyByCredentials(array $credentials = \[\], array $data = \[\]);
- updateManyByIds(array $ids, array $data = \[\]);
- function deleteOneById($id);
- public function allExist(array $ids);
- deleteOneBy($key, $value);
- deleteOneByCredentials(array $credentials = \[\]);
- deleteManyBy($key, $value);
- deleteManyByCredentials(array $credentials = \[\]);
- deleteManyByIds(array $ids);
- searchByCredentials(array $credentials = \[\], $perPage);
- with(array $with = \[\]);
- columns(array $columns = \['\*'\]);
- limit($limit = 10);
- orderBy($orderBy, $sort = 'DESC');

Usage
-----

[](#usage)

### Create a Model

[](#create-a-model)

Create your model normally, but it is important to define the attributes that can be filled from the input form data.

```
namespace App;

class Article extends Eloquent { // can be any other class name
    protected $fillable = [
        'name',
        'author',
        ...
     ];

     ...
}
```

### Create a RepositoryInteface

[](#create-a-repositoryinteface)

```
namespace App;
use Foo ;
use ra3oul\EloquentAbstractRepository\repository\RepositoryInterface;

interface ArticleRepositoryInterface extends RepositoryInterface
{

}
```

### Create a Repository

[](#create-a-repository)

```
namespace App;
use Foo ;
class ArticleRepository extends AbstractEloquentRepository implements ArticleRepositoryInterface

       public function __construct(Foo $model)
    {
        parent::__construct($model);
    }
}
```

### Create Service Provider

[](#create-service-provider)

in order to bind interfaces to repository classes we should create a simple service provider to bind them

```
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class RepositoryServiceProvider extends ServiceProvider
{
    protected function registeredRepositories()
    {
        // 'Repository Interface' => 'Implementation'
        return [
      '\App\ArticleRepositoryInterface' =>
                '\App\ArticleRepository',
                // you should add other interfaces and their implemented classes below !
        ];
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $repos = $this->registeredRepositories();

        foreach ($repos as $interface => $implemented) {
            $this->app->bind($interface, $implemented);
        }
    }
```

### Use methods

[](#use-methods)

```
namespace App\Http\Controllers;

use App\ArticleRepositoryInterface;

class ArticlesController extends BaseController {

    /**
     * @var ArticleRepository
     */
    protected $repository;

    public function __construct(FooRepositoryInterface $repository){
        $this->repository = $repository;
    }

    ....
}
```

Find all results in Repository

```
$articles = $this->repository->findAll();
```

Find all results in Repository with pagination

```
$aritcles = $this->repository->columns([*])->paginate($limit=10);
```

Find by result by id

```
$articles = $this->repository->findOneById($id);
```

Showing only specific attributes of the model

```
$article = $this->repository->columns(['id', 'state_id'])->findOneById($id);
```

Loading the Model relationships

```
$article = $this->repository->with(['state'])->findOneById($id);
```

Find by result by field name

```
$articles = $this->repository->findOneBy('country_id','15');
```

Find by result by field

```
$articles = $this->repository->findManyBy('name','rasoul');
```

Find by result by multiple values in id

```
$articles = $this->repository->findManyByIds([1,2,3,4,5]);
```

Create new entry in Repository

```
$article = $this->repository->create( Input::all() );
```

Update entry in Repository

```
$article = $this->repository->updateOneById(  $id , Input::all());
```

Delete entry in Repository

```
$this->repository->deleteOneById($id)
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3619d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fc909bb243f1363542bd2c949536ff0b6ff444af636ad76d31fbe3030308a76?d=identicon)[ra3oul](/maintainers/ra3oul)

---

Top Contributors

[![ra3oul](https://avatars.githubusercontent.com/u/8618409?v=4)](https://github.com/ra3oul "ra3oul (13 commits)")

### Embed Badge

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

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

PHPackages © 2026

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