PHPackages                             ulex/epic-repositories - 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. ulex/epic-repositories

ActiveProject[Framework](/categories/framework)

ulex/epic-repositories
======================

EPIC Repositories - An epic Laravel package

2.2.3(2y ago)37.6k↓68.9%MITPHPPHP ^7.4|^8.0

Since Dec 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/alexpilavakis/epic-repositories)[ Packagist](https://packagist.org/packages/ulex/epic-repositories)[ RSS](/packages/ulex-epic-repositories/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)DependenciesVersions (27)Used By (0)

Add a powerful core setup to your application's queries
=======================================================

[](#add-a-powerful-core-setup-to-your-applications-queries)

Documentation, Installation, and Usage Instructions
---------------------------------------------------

[](#documentation-installation-and-usage-instructions)

First, install the package via Composer:

```
composer require ulex/epic-repositories

```

---

 Service Provider
------------------

[](#-service-provider-)

### For Laravel

[](#for-laravel)

You should publish the RepositoriesServiceProvider:

```
php artisan vendor:publish --provider="Ulex\EpicRepositories\RepositoriesServiceProvider" --tag=epic-repositories-config
```

Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file: Laravel

```
'providers' => [
// ...
Ulex\EpicRepositories\RepositoriesServiceProvider::class,
];
```

### For Lumen

[](#for-lumen)

In your `bootstrap/app.php` add this:

```
$app->register(Ulex\EpicRepositories\RepositoriesServiceProvider::class);

```

---

 Config
--------

[](#-config-)

If config file `epic-repositories.php` was not published copy it to config folder with:

```
cp vendor/ulex/epic-repositories/config/epic-repositories.php config/epic-repositories.php

```

Take some time to review this config file. Here you can adjust various configurations for your repositories setup.

- Set a custom TTL for each of you models.
- Set the namespaces of your folders
- Enable/add the repositories and decorators you will use.
- Add your model bindings for each repository and which decorators to use for that repository.

#### Note: In order to use `elastic` repository you will have to add "elasticsearch/elasticsearch" package to your composer.json.

[](#note-in-order-to-use-elastic-repository-you-will-have-to-add-elasticsearchelasticsearch-package-to-your-composerjson)

 Create Repository/ies, Decorator/s with their Interfaces for a Model
----------------------------------------------------------------------

[](#-create-repositoryies-decorators-with-their-interfaces-for-a-model-)

#### First declare your models in `config/epic-repositories`

[](#first-declare-your-models-in-configepic-repositories)

```
...
'bindings' => [
        'eloquent' => [
            'decorators' => ['caching'],
            'models' => [
                'User' => App\Models\User::class,
                //'NewModel => App\Models\NewModel::class,
            ]
        ],
...
```

Run the following php artisan command:

```
php artisan make:epic
```

Depending on you configuration, the necessary folders &amp; classes will be created in your `app/Repositories` folder. Example:

```
UserEloquentRepository created successfully.
UserEloquentInterface created successfully.
UserEloquentCachingDecorator created successfully.
```

How to use
----------

[](#how-to-use)

This package provides an abstract structure that uses the Repository design pattern with caching decorator/s for you application.

Once installed you can create Repositories for your models that cache the data from your queries. Eloquent and Elastic Repositories are provided and ready to use if enabled. Follow the same principle for any data resource you have on your application.

```
# Example when injecting to a controller
use App\Repositories\Interfaces\UserEloquentInterface;

public function __construct(UserEloquentInterface $userRepository)
{
    $this->userRepository = $userRepository;
}

...

public function find($id)
{
    //retrieve from db and then cache the result
    $user = $this->userRepository->find($id);
    //retrieve straight from source, uncached
    $user = $this->userRepository->fromSource()->find($id);
}
```

Extending a model's CachingDecorator
------------------------------------

[](#extending-a-models-cachingdecorator)

For GET functions use the `remember` function the same way as in the AbstractCachingDecorator. This will ensure that this function is cached and invalidated properly.

#### Function `remember` signature

[](#function-remember-signature)

```
protected function remember(string $function, $arguments, bool $isCollection = false)
```

### Functions that return a single result:

[](#functions-that-return-a-single-result)

#### PostsEloquentCachingDecorator.php

[](#postseloquentcachingdecoratorphp)

```
public function getLatestPost($user_id)
    {
        return $this->remember(__FUNCTION__, func_get_args());
    }
```

**Note:** Remember to add the cache invalidation of the new function by extending flushGetKeys in the model's CachingDecorator.

```
public function flushGetKeys($model, $attributes = null)
{
    $this->flushFunction('getLatestPost', ['user_id' => $model->user_id]);
    parent::flushGetKeys($model, $attributes);
}
```

#### PostsEloquentRepository.php

[](#postseloquentrepositoryphp)

Add the query in the model's repository

```
public function getLatestPost($user_id)
{
    return $this->model->query()->where('user_id', '=', $user_id)->latest()->first();
}
```

### Functions that return a collection of results:

[](#functions-that-return-a-collection-of-results)

For GET functions that return collections you MUST pass `TRUE` to the $isCollection param on `remember` function.

```
public function getUserPosts($user_id)
{
    return $this->remember(__FUNCTION__, func_get_args(), true);
}
```

The above will be flushed in `flushGetKeys` which calls `flushCollections()`.

#### Note: If you are adding functions that create a new column, you need to add `$this->flushCollections();` after the entry is created so that all collections are flushed and can include your new entry/ies. Check `create` in AbstractCachingDecorator.

[](#note-if-you-are-adding-functions-that-create-a-new-column-you-need-to-add-this-flushcollections-after-the-entry-is-created-so-that-all-collections-are-flushed-and-can-include-your-new-entryies-check-create-in-abstractcachingdecorator)

Contributing
------------

[](#contributing)

This package is mostly based on [Jeffrey Way](https://twitter.com/jeffrey_way)'s awesome [Laracasts](https://laracasts.com) lessons when using the repository design pattern on [Laravel From Scratch](https://laracasts.com/series/laravel-6-from-scratch) series.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

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

Recently: every ~53 days

Total

26

Last Release

788d ago

Major Versions

1.3.6 → 2.0.02023-06-12

PHP version history (3 changes)1.0.0PHP ^7.0

1.0.1PHP ^7.3|^8.0

2.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c0d1398d65cb4a1f7a8665a941c8eef9a72c2415b460eea0c2a9cce19898361?d=identicon)[alexpilavakis](/maintainers/alexpilavakis)

---

Top Contributors

[![alexpilavakis](https://avatars.githubusercontent.com/u/46778251?v=4)](https://github.com/alexpilavakis "alexpilavakis (63 commits)")

### Embed Badge

![Health badge](/badges/ulex-epic-repositories/health.svg)

```
[![Health](https://phpackages.com/badges/ulex-epic-repositories/health.svg)](https://phpackages.com/packages/ulex-epic-repositories)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M297](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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