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 :)
hnabeel64/repopackage 适用场景与选型建议
hnabeel64/repopackage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hnabeel64/repopackage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hnabeel64/repopackage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-21