PHPackages                             vdhoangson/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. [Framework](/categories/framework)
4. /
5. vdhoangson/laravel-repository

ActiveLibrary[Framework](/categories/framework)

vdhoangson/laravel-repository
=============================

Repository pattern package for Laravel framework

v2.0.7(6mo ago)6296MITPHPPHP ^8.4CI failing

Since Jan 16Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/vdhoangson/laravel-repository)[ Packagist](https://packagist.org/packages/vdhoangson/laravel-repository)[ RSS](/packages/vdhoangson-laravel-repository/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

Laravel Repository
==================

[](#laravel-repository)

Repository pattern package for Laravel framework.

[![GitHub tag (latest by date)](https://camo.githubusercontent.com/b8e12b4b9bfe584d816fbec056593cc04648ae1b43f991836dc2af69a2af9e85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d646174652f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d56657273696f6e)](https://camo.githubusercontent.com/b8e12b4b9bfe584d816fbec056593cc04648ae1b43f991836dc2af69a2af9e85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d646174652f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d56657273696f6e)[![GitHub](https://camo.githubusercontent.com/88410895f34de68012535b9a50aa3a256714a897e55a68708f5efb1bedc1d998/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d4c6963656e7365)](https://camo.githubusercontent.com/88410895f34de68012535b9a50aa3a256714a897e55a68708f5efb1bedc1d998/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d4c6963656e7365)[![Packagist](https://camo.githubusercontent.com/2af9252d8511112ff51116e44d95c2bfd2eddb50d29578dfab185ae43a1e8c4e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d446f776e6c6f616473)](https://camo.githubusercontent.com/2af9252d8511112ff51116e44d95c2bfd2eddb50d29578dfab185ae43a1e8c4e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d446f776e6c6f616473)[![PHP from Packagist](https://camo.githubusercontent.com/c881fe32e6a6c595622e40e28eeb1990c938fea0f6e0b008e5622ba9ed2260e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d504850)](https://camo.githubusercontent.com/c881fe32e6a6c595622e40e28eeb1990c938fea0f6e0b008e5622ba9ed2260e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7664686f616e67736f6e2f6c61726176656c2d7265706f7369746f72793f6c6162656c3d504850)[![Tests](https://github.com/vdhoangson/laravel-repository/workflows/Tests/badge.svg)](https://github.com/vdhoangson/laravel-repository/workflows/Tests/badge.svg)

### Version compatibility

[](#version-compatibility)

#### Laravel

[](#laravel)

FrameworkPackageNote10.x.x^2.x.xPHP ^8.2 Supported.11.x.x^2.x.xPHP ^8.2 Supported.12.x.x^2.x.xPHP ^8.2 Supported.Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 10.x or higher

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

[](#installation)

You can install this package by composer:

```
composer require vdhoangson/laravel-repository

```

For more configuration, you can publish configuration file:

```
php artisan vendor:publish --tag=laravel-repository-config

```

Or using the provider:

```
php artisan vendor:publish --provider "Vdhoangson\LaravelRepository\Providers\LaravelRepositoryServiceProvider"

```

### Implementation

[](#implementation)

To use Repositories, create repository class that:

- Extend BaseRepository class
- Implements interface that extend BaseInterface

For example, this is implementation of repository for Example entity:

ExampleRepositoryInterface:

```
interface ExampleRepositoryInterface extends BaseInterface
{}
```

ExampleRepository class. This class has to implement entity() method, that return namespace of entity that will be used by repository.

```
class ExampleRepository extends BaseRepository implements ExampleRepositoryInterface
{
    /**
     * Model entity class that will be use in repository
     *
     * @return BaseInterface
     */
    public function entity(): string
    {
        return Example::class;
    }

}
```

### Using repositories

[](#using-repositories)

To use Repository in controller or other class you can use dependency injection or Container. Below is sample code of using service in controller.

```
class ExampleController extends Controller {

    /**
     * @var ExampleRepositoryInterface $exampleRepository
     */
    protected $exampleRepository;

    public function __construct(ExampleRepositorynterface $exampleRepository){
        $this->exampleRepository = $exampleRepository;
    }

    ....
}
```

#### Available methods

[](#available-methods)

- makeEntity() - make new entity instance
- getEntity() - return previously set entity instance
- setEntity() - set entity instance
- pushCriteria() - push new criteria to use in query (passed class must be implementation of BaseCriteria)
- popCriteria() - delete given criteria from use (if exist)
- getCriteria() - return collection of actualy set criteria
- applyCriteria() - apply criteria to use in query
- skipCriteria() - skip criteria in query
- clearCriteria() - clear criteria colleciton - delete all pushed criterias
- all(array $columns) - get all records
- get(array $columns) - get records (with criteria)
- first(array $columns) - get first record (with criteria)
- create(array $parameters) - create new entity record
- updateOrCreate(array $where, array $values) - update existing record, or create new
- update(int $id, array $parameters) - update entity by ID
- delete(int $id) - delete entity record by ID
- firstOrNew(array $where) - return first entity record if found, otherwise return new entity
- orderBy(string $column, string $direction) - order records by column
- with($relations) - add relations sub-query
- transactionBegin() - begin database transaction
- transactionCommit() - commit transaction
- transactionRollback() - rollback transaction
- findWhere(array $where, array $columns) - return all records that match where array
- findWhereIn(string $column, array $where, array $columns)
- findWhereNotIn(string $column, array $where, array $columns)
- findByField($field, $value = null, $columns = \['\*'\])
- chunk(int $limit, callable $callback, array $columns) - chunk query results
- count(array $columns) - count results
- paginate($perPage, $columns, $pageName, $page) - paginate results
- simplePaginate($perPage, $columns, $pageName, $page) - paginate results
- has($relation, $operator, $count, $bolean, $callback) - where has relation
- orHas($relation, $operator, $count) - or where has relation
- whereHas($relation, $callback, $operator, $count)
- orWhereHas($relation, $callback, $operator, $count)
- whereDoesntHave($relation, $callback)
- orWhereDoesntHave($relation, $callback)
- withCount($relations)
- doesntHave($relation, $boolean, $callback)
- orDoesntHave($relation)
- hasMorph($relation, $types, $operator, $count, $boolean, $callback)
- orHasMorph($relation, $types, $operator, $count)
- doesntHaveMorph($relation, $types, $boolean, $callback)
- orDoesntHaveMorph($relation, $types)
- whereHasMorph($relation, $types, $callback, $operator, $count)
- orWhereHasMorph($relation, $types, $callback, $operator, $count)
- whereDoesntHaveMorph($relation, $types, $callback)
- orWhereDoesntHaveMorph($relation, $types, $callback)
- sum($column)

#### Caching

[](#caching)

---

Information: In order to use Caching feature in repository, you must use cache driver that support tags. Actually "file" and "database" drivers are not supported.

More information in [in laravel documentation](https://laravel.com/docs/9.x/cache#cache-tags).

---

You can user criteria with this functions, and results will be cached.

Repository automatically flush cache, when method create(), updateOrCreate(), update(), delete() is call.

##### Skipping cache

[](#skipping-cache)

To force fetch data from database, skipping cached data, use skipCache() method. Example:

```
$this->repository->skipCache()->findWhere(...)
```

##### Disable cache

[](#disable-cache)

To quick disable cache i.ex for debugging, set REPOSITORY\_CACHE variable to false in .env

```
REPOSITORY_CACHE=false
```

### Use scopeQuery

[](#use-scopequery)

```
$data = $this->repository->scopeQuery(function($query){
    return $query->orderBy('sort_order','asc');
})->all();
```

Changelog
---------

[](#changelog)

Go to the [Changelog](CHANGELOG.md) for a full change history of the package.

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance66

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 91.8% 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 ~31 days

Recently: every ~15 days

Total

15

Last Release

207d ago

Major Versions

1.2.3 → 2.0.02025-07-01

PHP version history (2 changes)1.1.5PHP ^8.0|^8.1

2.0.0PHP ^8.4

### Community

Maintainers

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

---

Top Contributors

[![vdhoangson](https://avatars.githubusercontent.com/u/4547214?v=4)](https://github.com/vdhoangson "vdhoangson (45 commits)")[![vo-son-rcvn](https://avatars.githubusercontent.com/u/95597967?v=4)](https://github.com/vo-son-rcvn "vo-son-rcvn (4 commits)")

---

Tags

laravellaravel-frameworkrepositoryframeworklaravellaravel 11repository patternrepositoryphp 8.4laravel-repositoryvdhoangson

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3691.5k](/packages/codewithdennis-larament)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[mahabub/laravel-crud-and-repository-generator

laravel crud generator with repository pattern

111.7k](/packages/mahabub-laravel-crud-and-repository-generator)

PHPackages © 2026

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