alex-kudrya/laravel-repositories

Structured repository layer for Laravel with contracts, Eloquent adapters, cache decorators, autogenerated tests and CQRS-friendly bindings.

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/alex-kudrya/laravel-repositories

v1.0.3 2026-01-19 18:41 UTC

This package is auto-updated.

Last update: 2026-01-21 12:19:49 UTC


README

Total Downloads Version License PHP Version Require

Laravel Repositories

Structured repository layer for Laravel with contracts, Eloquent implementations, cache decorators and CQRS-friendly bindings.

This package provides a production-ready way to generate repositories with:

  • strict contracts
  • Eloquent adapters
  • optional cache decorators (with versioned cache keys)
  • automatic service container bindings
  • ready-to-run unit tests (PHPUnit or Pest)

Generated Repository Structure

root/
├── app/
│   └── Repositories/
│       ├── Contracts/
│       │   └── ProductRepositoryContract.php
│       └── Implementations/
│           ├── Eloquent/
│           │   └── ProductRepository.php
│           └── Cached/
│               └── ProductCacheRepository.php
└── tests/
    └── Unit/
        └── Repositories/
            ├── ProductRepositoryTest.php
            └── ProductCacheRepositoryTest.php

Installation

composer require alex-kudrya/laravel-repositories
// bootstrap/providers.php

return [
    ...
    \AlexKudrya\LaravelRepositories\Providers\RepositoriesServiceProvider::class,
 ]

For Laravel ≤10 the provider can also be registered in config/app.php.

Usage

The package ships with a single artisan command:

php artisan make:repository Product --model=Product

Or run it as an interactive wizard (recommended):

php artisan make:repository

What will be generated

By default it creates:

  • app/Repositories/Contracts/RepositoryContract.php
  • app/Repositories/Implementations/Eloquent/Repository.php
  • app/Repositories/Implementations/Cached/CacheRepository.php (optional)
  • app/Providers/RepositoryServiceProvider.php (created if missing)
  • service container bindings inside RepositoryServiceProvider

Cache decorator

If cache is enabled, the decorator uses versioned cache keys to invalidate all cached lists on write operations (create/update/delete) without tracking each individual key.

Publishing Stubs

You can publish stubs to customize generated code

php artisan vendor:publish --tag=laravel-repositories-stubs

Published to:

  • stubs/laravel-repositories

Testing (PHPUnit / Pest)

The generator can create repository unit tests compatible with PHPUnit or Pest. • If Pest is installed in your app, Pest-style tests will be generated. • Otherwise, PHPUnit tests will be generated.

The tests are designed to be green by default (no skipped, no incomplete, no model-field assumptions).

License

MIT

Alexander Kudria alexkudrya91@gmail.com