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

AbandonedArchivedLibrary[Framework](/categories/framework)

pacerit/laravel-repository
==========================

Standalone repository pattern package for Laravel and Lumen framework

5.0.0(4y ago)563511MITPHPPHP ^8.0

Since Oct 4Pushed 4y agoCompare

[ Source](https://github.com/pacerit/laravel-repository)[ Packagist](https://packagist.org/packages/pacerit/laravel-repository)[ RSS](/packages/pacerit-laravel-repository/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (5)Versions (58)Used By (1)

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

[](#laravel-repository)

Standalone repository pattern package for Laravel and Lumen framework.

[![GitHub tag (latest by date)](https://camo.githubusercontent.com/e3089f939f505b7bfff94ae50485e0fd4c5f9e17b6cc46d2e1fd2eb6a5336892/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d646174652f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d56657273696f6e)](https://camo.githubusercontent.com/e3089f939f505b7bfff94ae50485e0fd4c5f9e17b6cc46d2e1fd2eb6a5336892/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d646174652f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d56657273696f6e)[![GitHub](https://camo.githubusercontent.com/6b78cee9aa274b082db398ac2eeacba7f9d4805a6cd13a3e30622d1dcfd5da67/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d4c6963656e7365)](https://camo.githubusercontent.com/6b78cee9aa274b082db398ac2eeacba7f9d4805a6cd13a3e30622d1dcfd5da67/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d4c6963656e7365)[![Packagist](https://camo.githubusercontent.com/b7aa55a2f8f6fa45241547603d49aedefa3db6d0a4f381f6131fba7be099745e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d446f776e6c6f616473)](https://camo.githubusercontent.com/b7aa55a2f8f6fa45241547603d49aedefa3db6d0a4f381f6131fba7be099745e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d446f776e6c6f616473)[![PHP from Packagist](https://camo.githubusercontent.com/615d500c963938ae5e8650cf959ed71015d5e190f2a42998ac007c480eca0adc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d504850)](https://camo.githubusercontent.com/615d500c963938ae5e8650cf959ed71015d5e190f2a42998ac007c480eca0adc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706163657269742f6c61726176656c2d7265706f7369746f72793f6c6162656c3d504850)[![StyleCI](https://camo.githubusercontent.com/7e9d34c74b87e80302615734496a876a4d70d0f3d65025eaf2b474bb29a2a799/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3231323736303338322f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/212760382)[![Build Status](https://camo.githubusercontent.com/72efaadb6e7adcdc9e0442807369418983c2238fb6cff40ce82b71390fcb6b04/68747470733a2f2f7472617669732d63692e636f6d2f706163657269742f6c61726176656c2d7265706f7369746f72792e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/pacerit/laravel-repository)

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

[](#installation)

You can install this package by composer:

```
composer require pacerit/laravel-repository

```

For more configuration, you can publish configuration file:

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

```

### Version compatibility

[](#version-compatibility)

#### Laravel

[](#laravel)

FrameworkPackageNote5.8.x^1.x.xNo longer maintained.6.0.x^2.x.xBug fixes only.7.x.x^3.x.xBug fixes only.8.x.x^4.x.xPHP ^8.0 Supported from 4.1.09.x.x^5.x.x#### Lumen

[](#lumen)

FrameworkPackageNote5.8.x^1.1.xNo longer maintained.6.0.x^2.x.xBug fixes only.7.x.x^3.x.xBug fixes only.8.x.x^4.x.xPHP ^8.0 Supported from 4.1.09.x.x^5.x.x### Implementation

[](#implementation)

To use Repositories, create repository class that:

- Extend CoreRepository class
- Implements interface that extend CoreRepositoryInterface

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

ExampleRepositoryInterface:

```
interface ExampleRepositoryInterface extends CoreRepositoryInterface
{}
```

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

```
class ExampleRepository extends CoreRepository implements ExampleRepositoryInterface
{
    /**
     * Model entity class that will be use in repository
     *
     * @return CoreRepositoryInterface
     * @author Wiktor Pacer
     * @since 2019-07-05
     */
    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 CoreRepositoryCriteria)
- 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)
- 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)

##### Additional methods (Laravel only)

[](#additional-methods-laravel-only)

- datatable() - return EloquentDataTable instance for records. In order to user with method, you must install suggested "yajra/laravel-datatables-oracle" package, and add "WithDatatable" trait in your repository of choice.

#### Built-in criteria

[](#built-in-criteria)

List of criteria, provider by default with this package:

- DateCriteria - search records with given date range
- FindWhereCriteria
- FindWhereInCriteria
- FindWhereNotInCriteria
- LimitCriteria
- OrWhereCriteria
- Select2Criteria - criteria useful when implementing Select2
- OffsetCriteria
- FindWhereOrWhereCriteria

#### 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/6.0/cache#cache-tags).

---

To use caching in CoreRepository implementation, simply add WithCache trait in your repository of choice. Trait will handle cache for methods:

- all()
- get()
- first()
- firstOrNew()
- firstOrNull()
- findWhere()
- findWhereIn()
- findWhereNotIn()
- paginate()
- simplePaginate()
- count()
- sum()

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

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

##### Tag by user ID

[](#tag-by-user-id)

By default repository cache adding actual authenticated user ID as tag. That provide possibility to separate cached data among users. That feature is useful for entities strictly associated to User (i.e. Account operation, Account details), when cached data will be flushed for each user separately - not for all repository, with save resources.

But for other entities (.i.e. Articles in CMS system), this solution can be annoying, so to disable this feature for selected repository call skipUserTag() method in \_\_construct(). Example:

```
class ExampleRepository extends CoreRepository implements ExampleRepositoryInterface
{

    use WithCache;

    /**
     * ExampleRepository constructor.
     *
     * @param Container $app
     * @throws RepositoryEntityException
     * @throws BindingResolutionException
     */
    public function __construct(Container $app)
    {
        parent::__construct($app);
        $this->skipUserTag();
    }

}
```

In some situation (i.e. in Jobs or Commands) you may want to manually update user data, and flush tagged cache for him. You can use setUserTag () function to manually set user ID for cache tag. To clear it use clearUserTag() function.

##### Skipping cache

[](#skipping-cache)

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

```
$this-exampleService->getRepository->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
```

Changelog
---------

[](#changelog)

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

Testing
-------

[](#testing)

```
composer test

```

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within package, please send an e-mail to Wiktor Pacer via . All security vulnerabilities will be promptly addressed.

License
-------

[](#license)

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

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity77

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

Recently: every ~90 days

Total

51

Last Release

1546d ago

Major Versions

2.0.13 → 3.0.82020-09-09

2.0.14 → 4.0.02020-09-09

2.0.15 → 4.1.02020-12-09

2.0.16 → 4.x-dev2021-02-21

2.x-dev → 5.0.02022-02-16

PHP version history (5 changes)1.0.0PHP ^7.2

1.0.7PHP ^7.1

4.0.0PHP ^7.3

4.1.0PHP ^7.3|^8.0

5.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53344063?v=4)[Wiktor Pacer](/maintainers/WiktorPacer)[@WiktorPacer](https://github.com/WiktorPacer)

---

Top Contributors

[![WiktorPacer](https://avatars.githubusercontent.com/u/53344063?v=4)](https://github.com/WiktorPacer "WiktorPacer (83 commits)")

---

Tags

eloquentlaravellaravel-repositorylumenphprepositoryrepository-patternframeworklaravelrepositorypaceritlaravel-repository

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/lumen-framework

The Laravel Lumen Framework.

1.5k26.2M709](/packages/laravel-lumen-framework)[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)

PHPackages © 2026

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