derakht/repository-pattern
Composer 安装命令:
composer require derakht/repository-pattern
包简介
Implement repository pattern design with a command
README 文档
README
Generate repository structure with single command
This package generates repository pattern files related to a model to use them in your app.
Installation
Require this package with composer using the following command:
composer require derakht/repository-pattern
Configuration
Publish the configuration file with th following command.
php artisan vendor:publish --provider="Derakht\RepositoryPattern\RepositoryPatternServiceProvider"
You can change default paths in this file.
Usage
You can now run the below command to create repository files.
php artisan make:repository ModelName
Example
php artisan make:repository Post
PostController.php
<?php namespace App\Http\Controllers; use App\Repositories\Contract\PostRepositoryInterface; class PostController extends Controller { public $postRepository; public function __construct() { $this->postRepository = app(PostRepositoryInterface::class); } public function index() { return $this->postRepository->all(); } }
or if you want to use injection add App\Providers\RepositoryServiceProvider::class to provider array in config/app.php.
PostController.php
<?php namespace App\Http\Controllers; use App\Repositories\Contract\PostRepositoryInterface; class ReportController extends Controller { public $postRepository; public function __construct(PostRepositoryInterface $postRepository) { $this->postRepository = $postRepository; } public function index() { return $this->postRepository->all(); } }
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-21