定制 hnabeel64/repopackage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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. ;)

  1. Install package by this command composer require hnabeel64/repopackage

  2. Then publish the vendor php artisan vendor:publish --tag=repository

  3. 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 define protected $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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固