alex-kudrya/laravel-repositories
Composer 安装命令:
composer require alex-kudrya/laravel-repositories
包简介
Structured repository layer for Laravel with contracts, Eloquent adapters, cache decorators, autogenerated tests and CQRS-friendly bindings.
README 文档
README
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)
Architectural Position
Repositories are not the canonical Laravel path for every model interaction, and this package does not try to replace Eloquent. It treats repositories as a pragmatic boundary for applications that want cleaner service, action, job and controller code:
- depend on contracts from business code
- keep persistence details inside Eloquent implementations
- keep cache behavior in decorators
- use typed repository methods that work with integer, UUID and ULID model keys
- avoid generic abstraction when a direct Eloquent query is clearer
Generated Repository Structure
root/
├── app/
│ └── Repositories/
│ ├── Contracts/
│ │ └── ProductRepositoryContract.php
│ └── Implementations/
│ ├── Eloquent/
│ │ └── ProductRepository.php
│ └── Cached/
│ └── ProductCacheRepository.php
└── tests/
├── Feature/
│ └── Repositories/
│ └── ProductRepositoryTest.php
└── Unit/
└── Repositories/
└── ProductCacheRepositoryTest.php
Installation
composer require alex-kudrya/laravel-repositories
The package service provider is auto-discovered by Laravel 11, 12 and 13.
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)
- App\Providers\RepositoryServiceProvider::class registration in bootstrap/providers.php
- 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.
Use --no-cache to bind the contract directly to the Eloquent implementation. If cached artifacts already exist, run --no-cache --force to remove the generated cached repository and cache test.
Publishing Stubs
You can publish stubs to customize generated code
php artisan vendor:publish --tag=laravel-repositories-stubs
Published to:
- stubs/laravel-repositories
Laravel Boost
This package ships with Laravel Boost resources:
resources/boost/guidelines/core.blade.phpresources/boost/skills/laravel-repositories-development/SKILL.md
When a consuming application installs Laravel Boost and runs php artisan boost:install or php artisan boost:update --discover, Boost can include these package-specific guidelines and the repository development skill.
This repository also keeps matching local AI resources under .ai/guidelines and .ai/skills for direct agent use while developing the package.
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 avoid model-field assumptions. Model-bound repository tests still require the referenced model and its table/migration to exist in the consuming application.
License
MIT
Alexander Kudria alexkudrya91@gmail.com
alex-kudrya/laravel-repositories 适用场景与选型建议
alex-kudrya/laravel-repositories 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alex-kudrya/laravel-repositories 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alex-kudrya/laravel-repositories 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-19