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

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

herojhc/laravel-repository
==========================

Laravel Repository

2.2.6(5y ago)1365MITPHPPHP &gt;=7.1CI failing

Since Jan 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/herojhc/laravel-repository)[ Packagist](https://packagist.org/packages/herojhc/laravel-repository)[ Docs](https://www.wfhtmc.com)[ RSS](/packages/herojhc-laravel-repository/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (8)Versions (22)Used By (0)

laravel-repository
==================

[](#laravel-repository)

> - l5-repository simple

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

[](#installation)

### Composer

[](#composer)

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

```
composer require herojhc/laravel-repository

```

### Laravel

[](#laravel)

#### &gt;= laravel5.5

[](#-laravel55)

ServiceProvider will be attached automatically

#### Other

[](#other)

In your `config/app.php` add `Herojhc\Repositories\Providers\RepositoryServiceProvider::class` to the end of the `providers` array:

```
'providers' => [
    ...
    Herojhc\Repositories\Providers\RepositoryServiceProvider::class,
],
```

If Lumen

```
$app->register(Herojhc\Repositories\Providers\LumenRepositoryServiceProvider::class);
```

Publish Configuration

```
php artisan vendor:publish --provider "Herojhc\Repositories\Providers\RepositoryServiceProvider"
```

Methods
-------

[](#methods)

### Herojhc\\Repositories\\Contracts\\RepositoryInterface

[](#herojhcrepositoriescontractsrepositoryinterface)

- all($columns = array('\*'))
- first($columns = array('\*'))
- paginate($limit = null, $columns = \['\*'\])
- find($id, $columns = \['\*'\])
- findBy($field, $value, $columns = \['\*'\])
- findWhere(array $where, $columns = \['\*'\])
- findWhereIn($field, array $where, $columns = \[\*\])
- findWhereNotIn($field, array $where, $columns = \[\*\])
- create(array $attributes)
- update(array $attributes, $id)
- updateOrCreate(array $attributes, array $values = \[\])
- delete($id)
- deleteWhere(array $where)
- orderBy($column, $direction = 'asc');
- with(array $relations);
- has(string $relation);
- whereHas(string $relation, closure $closure);
- hidden(array $fields);
- visible(array $fields);
- scopeQuery(Closure $scope);
- getFieldsSearchable();

### Herojhc\\Repositories\\Contracts\\CriteriaInterface

[](#herojhcrepositoriescontractscriteriainterface)

- pushCriteria($criteria)
- popCriteria($criteria)
- getCriteria()
- getByCriteria(CriteriaInterface $criteria)
- skipCriteria($status = true)
- getFieldsSearchable()

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 Post extends Eloquent { // or Ardent, Or any other Model Class

    protected $fillable = [
        'title',
        'author',
        ...
     ];

     ...
}
```

### Create a Repository

[](#create-a-repository)

```
namespace App;

use Herojhc\Repositories\Eloquent\BaseRepository;

class PostRepository extends BaseRepository {

    /**
     * Specify Model class name
     *
     * @return string
     */
    function model()
    {
        return "App\\Post";
    }
}
```

### Create a Criteria

[](#create-a-criteria)

#### Using the command

[](#using-the-command)

```
php artisan make:criteria My

```

Criteria are a way to change the repository of the query by applying specific conditions according to your needs. You can add multiple Criteria in your repository.

```
use Herojhc\Repositories\Contracts\RepositoryInterface;
use Herojhc\Repositories\Criteria\Criteria;

class MyCriteria extend Criteria {

    public function apply($model, RepositoryInterface $repository)
    {
        $model = $model->where('user_id','=', Auth::user()->id );
        return $model;
    }
}
```

### Using the Criteria in a Controller

[](#using-the-criteria-in-a-controller)

```
namespace App\Http\Controllers;

use App\PostRepository;

class PostsController extends BaseController {

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

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

    public function index()
    {
        $this->repository->pushCriteria(new MyCriteria1());
        $this->repository->pushCriteria(MyCriteria2::class);
        $posts = $this->repository->all();
		...
    }

}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

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

Recently: every ~72 days

Total

21

Last Release

2141d ago

Major Versions

0.16.5 → 2.1.02018-11-15

PHP version history (2 changes)0.16.3PHP &gt;=5.5.9

2.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7a06bb36db32aa8879196c4c48ff91959c2101f33234ef668235dce6f852fd19?d=identicon)[herojhc](/maintainers/herojhc)

---

Top Contributors

[![herojhc](https://avatars.githubusercontent.com/u/25656502?v=4)](https://github.com/herojhc "herojhc (29 commits)")

---

Tags

laraveldatabaseeloquentrepositoryrepositories

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[toponepercent/baum

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

3154.7k](/packages/toponepercent-baum)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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