moffhub/maker-checker 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

moffhub/maker-checker

最新稳定版本:v0.0.13

Composer 安装命令:

composer create-project moffhub/maker-checker

包简介

A laravel package to help manage with maker checker tight requirement

README 文档

README

MakerChecker is a package that provides a simple way to implement the Maker-Checker pattern in your Laravel application.

Installation

You can install the package via composer:

composer require moffhub/maker-checker

This package depends on the sourcetoad\enhanced-resources which you can install via composer:

composer require sourcetoad\enhanced-resources

You can publish the config file with:

php artisan vendor:publish --provider="Moffhub\MakerChecker\MakerCheckerServiceProvider" --tag="config"

This is the contents of the published config file:

Usage

First, you need to add the ChecksRequests trait to the model you want to check against for roles and permissions typically the User Model.

use Moffhub\MakerChecker\Traits\ChecksRequests;

class Post extends Model
{
    use ChecksRequests;
}

Then, you can use the makerChecker method to create a new record.

 if (auth()->user()->requiresApproval('create', Post::class)) {
            $approvalRequest = MakerChecker::request()
                ->toExecute(
                    $approvableActionClass,
                    (array) $data,
                )
                ->madeBy(auth()->user())
                ->description('Create Posts')
                ->save();

            return MakerCheckerResource::make($approvalRequest)
                ->format(MakerCheckerResource::SIMPLE)
                ->response()
                ->setStatusCode(Response::HTTP_MULTI_STATUS);
        }

Approvable actions

This library supports create, delete, update and execute actions. You can create your own actions by extending the ApprovableAction class.

This is configured by either calling

for execute Additionally you can pass an array of roles that can approve the request and the number of approvals required for the request to be approved by each role

MakerChecker::request()->toExecute(
                    $approvableActionClass,
                    (array) $data,
                    [
                        'admin'=> 2,
                        'client' => 3,
                    ],
                )

or for create

MakerChecker::request()->toCreate(
                    $createActionClass,
                    (array) $data,
                )

or for update

MakerChecker::request()->toUpdate(
                    $updateActionClass,
                    (array) $data,
                )

or for delete

MakerChecker::request()->toDelete(
                    $deleteActionClass,
                    (array) $data,
                )

统计信息

  • 总下载量: 7.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-28