blaisebueno/laravel-repository
Composer 安装命令:
composer require blaisebueno/laravel-repository
包简介
A Laravel package implementing a clean, scalable repository design pattern architecture to abstract data persistence and promote testable, maintainable code.
关键字:
README 文档
README
A Laravel package implementing a clean, scalable repository design pattern architecture to abstract data persistence and promote testable, maintainable code.
Installation
Step 1: Install via Composer
Run the following command in your Laravel project:
composer require blaisebueno/laravel-repository
Step 2: Register the Service Provider for Publishing
If you are using Laravel 5.5+ with package auto-discovery, you can skip this step.
Otherwise, you need to manually register the service provider.
For Laravel 10 and Below
Add the service provider in config/app.php:
For Laravel 11 and Above
Add the service provider in bootstrap/providers.php:
\BlaiseBueno\LaravelRepository\LaravelRepositoryServiceProvider::class,
Step 3: Publish Files
Run the following command to publish the repository stubs:
php artisan vendor:publish --provider="BlaiseBueno\LaravelRepository\LaravelRepositoryServiceProvider"
This will publish the following:
app/Providers/RepositoryServiceProvider.phpapp/Console/Commands/MakeRepository.phpapp/Repositories/BaseRepository.phpapp/Repositories/Interfaces/EloquentInterface.php
Adding --force flag will overwrite existing files.
Step 4: Register the Repository Service Provider
For Laravel 10 and Below
Add the service provider in config/app.php:
For Laravel 11 and Above
Add the service provider in bootstrap/providers.php:
App\Providers\RepositoryServiceProvider::class,
Step 5: Register the make:repository Command
⚠️ In Laravel 11 and above,
Kernel.phphas been removed. Custom commands inapp/Console/Commandsare now auto-discovered.
⚠️ If your
App\Console\Kernelcontains the default line below, no manual registration is required:
$this->load(__DIR__.'/Commands');
If you're using a custom path or want to register explicitly, add the following in app/Console/Kernel.php:
protected $commands = [ \App\Console\Commands\MakeRepository::class, ];
Step 6: Usage
You can now generate a new repository using:
php artisan make:repository User
This will create:
app/Repositories/UserRepository.phpapp/Repositories/Interfaces/UserInterface.php
Adding --force flag will overwrite existing files.
If you want to generate a corresponding service file, add the --s flag:
This will additionally create:
app/Services/UserService.php
Modify these files according to your needs.
License
This package is open-source and available under the MIT license.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-26