me-arif-dewan/laravel-repository-generator
Composer 安装命令:
composer require me-arif-dewan/laravel-repository-generator
包简介
Introduces a new Artisan command to generate repository classes with support for: - Multiple interface implementation with automatic method stub generation. - Single class extension with validation. - Model dependency injection via constructor. - Automatic service provider binding registration. - Pi
关键字:
README 文档
README
A powerful, type-safe repository pattern generator for Laravel applications with advanced features including interface implementation, model injection, and automatic service provider binding.
Features
- Multiple Interface Implementation - Implement multiple interfaces with automatic method stub generation
- Class Extension - Extend base repository classes with validation
- Model Dependency Injection - Auto-inject Eloquent models via constructor
- Auto-Binding - Automatically register bindings in service providers
- Smart Type Resolution - Intelligent type hint resolution and use statement generation
- Pipeline Architecture - Clean, maintainable code using Laravel Pipeline
- Comprehensive Validation - Robust error handling with custom exceptions
- Fully Tested - 100% test coverage with Pest
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
Installation
Install the package via Composer:
composer require me-arif-dewan/laravel-repository-generator --dev
Quick Start
Basic Repository
php artisan make:repository UserRepository
Generates:
<?php namespace App\Repositories; class UserRepository { }
With Model Injection
php artisan make:repository UserRepository --model=User
Generates:
<?php namespace App\Repositories; use App\Models\User; class UserRepository { /** * Create a new repository instance. */ public function __construct( protected User $model ) {} }
With Interface Implementation
php artisan make:repository UserRepository --interface=UserRepositoryInterface
Generates:
<?php namespace App\Repositories; use App\Contracts\UserRepositoryInterface; use Illuminate\Support\Collection; class UserRepository implements UserRepositoryInterface { public function find(int $id): ?User { // TODO: Implement find() method. } public function all(): Collection { // TODO: Implement all() method. } }
Complete Example
php artisan make:repository UserRepository \ --model=User \ --extends=Repositories/BaseRepository \ --interface=UserInterface,PaymentInterface \ --bind \ --force
Generates:
<?php namespace App\Repositories; use App\Models\User; use App\PaymentInterface; use App\Repositories\BaseRepository; use App\UserInterface; class UserRepository extends BaseRepository implements UserInterface, PaymentInterface { /** * Create a new repository instance. */ public function __construct( protected User $model ) {} public function find(int $id): ?User { // TODO: Implement find() method. } public function processPayment(array $data): bool { // TODO: Implement processPayment() method. } }
And automatically updates app/Providers/AppServiceProvider.php:
public function register(): void { $this->app->bind(UserInterface::class, UserRepository::class); $this->app->bind(PaymentInterface::class, UserRepository::class); }
Available Options
| Option | Short | Description |
|---|---|---|
--interface |
-i |
Implement interface(s), comma-separated |
--extends |
-e |
Extend parent class |
--model |
-m |
Inject model dependency |
--bind |
-b |
Auto-register bindings |
--force |
-f |
Overwrite existing file |
Advanced Usage
Multiple Interfaces
php artisan make:repository PaymentRepository \ --interface=PaymentInterface,LoggableInterface,AuditableInterface
Nested Namespaces
php artisan make:repository UserRepository \ --interface=Contracts/User/UserRepositoryInterface \ --extends=Domain/Repositories/BaseRepository
Custom Stub
Publish the stub for customization:
php artisan vendor:publish --tag="laravel-repository-generator-stubs"
Edit stubs/repository.stub to match your preferences.
Testing
# Run tests composer test # Run tests with coverage composer test-coverage # Run static analysis composer analyse # Fix code style composer format
Error Handling
The package provides comprehensive error messages:
# Multiple inheritance php artisan make:repository UserRepository --extends=Base,Another # Error: PHP does not support multiple inheritance. You can only extend one class. # Non-existent interface php artisan make:repository UserRepository --interface=NonExistent # Error: Interface [App\NonExistent] does not exist. # Extending an interface php artisan make:repository UserRepository --extends=UserInterface # Error: [App\UserInterface] is an interface. Use --interface instead of --extends.
Architecture
Clean Architecture
src/
├── Commands/ → Artisan commands
├── Services/ → Business logic
├── Support/ → Utility classes
├── Contracts/ → Interfaces
├── Exceptions/ → Custom exceptions
├── Enums/ → Enumerations
└── Concerns/ → Reusable traits
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email cseknowledge@gmail.com instead of using the issue tracker.
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
Credits
Acknowledgments
Built with Spatie's Package Skeleton
me-arif-dewan/laravel-repository-generator 适用场景与选型建议
me-arif-dewan/laravel-repository-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「repository」 「command」 「laravel」 「artisan」 「repository-pattern」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 me-arif-dewan/laravel-repository-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 me-arif-dewan/laravel-repository-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 me-arif-dewan/laravel-repository-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A Wrapper for exec and it's results
repository php library
Symfony bundle to monitor and execute commands
Shell command module for PHP.
Library with classes to help you do batch.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-26
