PHPackages                             mike-zange/laravel-entity-base-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. [Caching](/categories/caching)
4. /
5. mike-zange/laravel-entity-base-repositories

ActiveLibrary[Caching](/categories/caching)

mike-zange/laravel-entity-base-repositories
===========================================

Simple base repositories for Laravel's Eloquent ORM, this packages abstracts the base Model functions and adds a caching decorator

0.5.0(7y ago)243MITPHPPHP ^7.1.3

Since Aug 1Pushed 7y agoCompare

[ Source](https://github.com/MikeZange/laravel-entity-base-repositories)[ Packagist](https://packagist.org/packages/mike-zange/laravel-entity-base-repositories)[ RSS](/packages/mike-zange-laravel-entity-base-repositories/feed)WikiDiscussions master Synced yesterday

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

Description
-----------

[](#description)

Simple base repositories for Laravel's Eloquent ORM, this packages abstracts the base Model functions and adds a caching decorator.

Caching is handled automatically if you have selected a caching method that allows tagging and cache is enabled in the config.

Requirements
------------

[](#requirements)

- `PHP ^7.1.3`

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

[](#installation)

1. As always: back up your database - I am not responsible for any data loss
2. Install the package via Composer:

    `composer require mike-zange/laravel-entity-base-repositories`
3. The service provider is auto-loaded in Laravel &gt;= 5.5
4. Publish the configuration file `repository.php`

    `php artisan vendor:publish --provider="MikeZange\LaravelEntityRepositories\Providers\RepositoryServiceProvider"`
5. You can create a repository using the following command

    `php artisan generate:repository {entity}`

    This will create the Contract, Eloquent and Cache decorator for the entity.

    `app/Repositories/UserRepository.php``app/Repositories/Eloquent/EloquentUserRepository.php``app/Repositories/Cache/CacheUserRepository.php`

    Customise the generated files with:

    Change the namespace, default: "App\\Repositories":

    `php artisan generate:repository {entity} --s App\\New\\Namespace`

    Change the repository name, default: "{entity}Repository":

    `php artisan generate:repository {entity} --r NewRepoName`

    Will generate: `NewRepoName`

    `app/Repositories/NewRepoName.php``app/Repositories/Eloquent/EloquentNewRepoName.php``app/Repositories/Cache/CacheNewRepoName.php`
6. Edit the config at `config/repository.php` to your requirements, the defaults should be okay for most uses, but you need to specify your repositories, for example:

    ```
    'repositories' => [
         [
             'entity' => \App\Entities\User::class,
             'contract' => App\Repositories\UserRepository::class,
             'eloquent_repository' => App\Repositories\Eloquent\EloquentUserRepository::class,
             'cache_decorator' => App\Repositories\Cache\CacheUserDecorator::class,
         ]
     ],

    ```
7. You can now type-hint your repositories in your controllers:

    ```
    class UserController extends Controller
    {
        /**
         * @var UserRepository
         */
        private $userRepository;

        /**
         * Create a new controller instance.
         *
         * @param UserRepository $userRepository
         */
        public function __construct(UserRepository $userRepository)
        {
            $this->userRepository = $userRepository;
        }

        public function index(Request $request)
        {
            $users = $this->userRepository->all();
            return $users;
        }
    }

    ```

Manually create a repository
----------------------------

[](#manually-create-a-repository)

1. Create a contract for your repository:

    ```
    namespace App\Repositories;

    use MikeZange\LaravelEntityRepositories\Repositories\BaseRepository;

    interface UserRepository extends BaseRepository
    {
    }

    ```
2. Create an Eloquent Repository for your Model:

    ```
    namespace App\Repositories\Eloquent;

    use App\Repositories\UserRepository;
    use MikeZange\LaravelEntityRepositories\Repositories\Eloquent\EloquentBaseRepository;

    class EloquentUserRepository extends EloquentBaseRepository implements UserRepository
    {
    }

    ```
3. Create a Cache Decorator for your Repository:

    ```
    namespace App\Repositories\Cache;

    use App\Repositories\UserRepository;
    use MikeZange\LaravelEntityRepositories\Repositories\Cache\CacheBaseDecorator;

    class CacheUserDecorator extends CacheBaseDecorator implements UserRepository
    {
        public function __construct(UserRepository $repository)
        {
            parent::__construct();
            $this->entityName = 'user';
            $this->repository = $repository;
        }
    }

    ```
4. Edit the config at `config/repository.php` to your requirements, the defaults should be okay for most uses, but you need to specify your repositories, for example:

    ```
    'repositories' => [
         [
             'entity' => \App\Entities\User::class,
             'contract' => App\Repositories\UserRepository::class,
             'eloquent_repository' => App\Repositories\Eloquent\EloquentUserRepository::class,
             'cache_decorator' => App\Repositories\Cache\CacheUserDecorator::class,
         ]
     ],

    ```
5. You can now type-hint your repositories in your controllers:

    ```
    class UserController extends Controller
    {
        /**
         * @var UserRepository
         */
        private $userRepository;

        /**
         * Create a new controller instance.
         *
         * @param UserRepository $userRepository
         */
        public function __construct(UserRepository $userRepository)
        {
            $this->userRepository = $userRepository;
        }

        public function index(Request $request)
        {
            $users = $this->userRepository->all();
            return $users;
        }
    }

    ```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Recently: every ~53 days

Total

6

Last Release

2626d ago

### Community

Maintainers

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

---

Top Contributors

[![mikezange](https://avatars.githubusercontent.com/u/5443707?v=4)](https://github.com/mikezange "mikezange (9 commits)")

---

Tags

cachedecoratorlaravelmodelpatternphprepositorysimplelaravelmodelrepository

### Embed Badge

![Health badge](/badges/mike-zange-laravel-entity-base-repositories/health.svg)

```
[![Health](https://phpackages.com/badges/mike-zange-laravel-entity-base-repositories/health.svg)](https://phpackages.com/packages/mike-zange-laravel-entity-base-repositories)
```

###  Alternatives

[crcms/repository

Detached model and controller warehouse data provider

674.4k3](/packages/crcms-repository)

PHPackages © 2026

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