hnabeel64/repopackage
Composer 安装命令:
composer require hnabeel64/repopackage
包简介
Repository pattern made easy in laravel By hnabeel64
README 文档
README
Make Repository service class, Interfaces and predefined methods and model with just one command. Simple to Medium CRUD generator ease of development for repository pattern followers.
The repopackage is the idea of repository design pattern implementation for beginner to intermediate developer. Time savour for the developer just install the package and publish assets. Don't need to add Model manually just run the command and repopackage will take care the other things. ;)
-
Install package by this command
composer require hnabeel64/repopackage -
Then publish the vendor
php artisan vendor:publish --tag=repository -
Now When a new table exist and you want to make a crud for it just write on console
php artisan repository:make {TableName}if you want a model too it asks for model confirmation you just have to defineprotected $fillable = [];into model and just try catch the methods on controller.
Usage
Repository pattern is easy to use as:
when you publish the vendor and make a new repository through command, this Base Interface come with pre defined methods such as:
public function findAll(): Collection; public function findById($id): ?Model; public function storeRecord(array $array): ?Model; public function updateRecord($id, array $array): bool; public function deleteRecord($id): bool; public function findLatest(): Model; public function findByUpdated(): Model;
These are predefined methods in repository and Interface have and both are bind on service container through service provider dynamically.
Child Interface contain following extra methods
public function findAll(): Collection; public function findById($id): ?Model; public function storeRecord(array $array): ?Model; public function updateRecord($id, array $array): bool; public function deleteRecord($id): bool; public function findLatest(): Model; public function findByUpdated(): Model; public function findBy($field, $value): ?Model; public function search($field, $value): ?Model;
⚠️ NOTE: you have to implement these methods in controller with try catch blocks. Import the repository class through dependency-injection Example
use App\Repository\SlugRepository; private $slug; public function __construct(SlugRepository $slug) { $this->slug = $slug; } public function search(Request $request) { try { $name = $request->name; $field = 'name'; $result = $this->slug->search($field, $name); if(!empty($result)) { return $result; } return 'no record found'; } catch (\Throwable $th) { return $th; } }
If you find any vulnerability or issue you can contact me on my email or open an issue here. any contributor are welcome :)
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-21