定制 jefremassingue/spatie-permission-generate 二次开发

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

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

jefremassingue/spatie-permission-generate

最新稳定版本:v1.0.0

Composer 安装命令:

composer require jefremassingue/spatie-permission-generate

包简介

Package for genarate permissions

README 文档

README

Spatie Permission Generate is a package that generates permissions for spatie/laravel-permission based on the directory, controller class name, and methods.

For instance, Admin\UserController with index method => will have the permission admin-user-index.

Installation

You can install the package via composer:

composer require jefremassingue/spatie-permission-generate:"dev-main"

Usage

Before using the package, you need to install and configure spatie/laravel-permission (https://github.com/spatie/laravel-permission).

// Run synchronizelPermission method to generate permissions
    $hasGenarate = \Jefre\SpatiePermissionGenerate\SpatiePermissionGenerate::synchronizelPermission();
// Change the guard name for permissions with a given prefix
    $numPermissionsUpdated = \Jefre\SpatiePermissionGenerate\SpatiePermissionGenerate::changeGuardWithPrefix('api-', 'api');
    

Instalation in Laravel

// Set the following keys in your `.env` file:

SPG_CONTROLLERS_ROOT_PATH='app/Http/Controllers'
SPG_IGNORE_CLASSES_FILES='Controller,Helper\Upload, Other classes you want ignore'
SPG_CONTROLLER_CLASSES_SUFFIX='Controller,_controller'
SPG_IGNORE_METHODS_AND_FUNCTIONS='__construct'
SPG_DEFAULT_GUARD='web'
KeyDescriptionExample
SPG_CONTROLLERS_ROOT_PATHThe root path where the controllers are located. You have to use `/`app/Http/Controllers
SPG_IGNORE_CLASSES_FILESThe classes that should be ignored (separated by comma). You have to use `\`'Controller,Admin\PermissionGeneratorController,Helper\Upload'
SPG_CONTROLLER_CLASSES_SUFFIXThe suffixes for the controller classes.'_controller,Controller'
SPG_IGNORE_METHODS_AND_FUNCTIONSThe methods and functions that should be ignored (separated by comma).'__construct,pay'
SPG_DEFAULT_GUARDThe default guard.'web'

Testing

To run the tests, execute the following command:

composer test

Example

Consider a file located in /app/Http/Controllers/API/UserController.php:

<?php

namespace App\Http\Controllers\API;

...

class UserController extends Controller
{
    public function __construct() {}
    public function index(){}
    public function create(){}
    public function store(Request $request){}
    public function show($id){}
    public function edit($id){}
    public function update(Request $request, $id){}
    public function destroy($id){}
}

The generated permissions would be:

api-user-index api-user-create api-user-store api-user-show api-user-edit api-user-update api-user-destroy

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jefre.dev@gmail.com or albinomateve@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-31