定制 rickgoemans/laravel-permission-service 二次开发

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

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

rickgoemans/laravel-permission-service

最新稳定版本:v6.0.0

Composer 安装命令:

composer require rickgoemans/laravel-permission-service

包简介

A Laravel permission helper service

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require rickgoemans/laravel-permission-service

You can publish the config file with:

php artisan vendor:publish --tag="laravel-permission-service-config"

This is the contents of the published config file:

<?php

use Rickgoemans\LaravelPermissionService\Enums\PermissionAction;

// config for Rickgoemans/LaravelPermissionService
return [
    /*
     * The separator that's being used between the model it's name and the action.
     */
    'separator'    => '.',

    /*
     * The names of the methods that reflect the action.
     */
    'action_names' => [
        PermissionAction::VIEW->value         => 'view',
        PermissionAction::CREATE->value       => 'create',
        PermissionAction::UPDATE->value       => 'update',
        PermissionAction::DELETE->value       => 'delete',
        PermissionAction::RESTORE->value      => 'restore',
        PermissionAction::FORCE_DELETE->value => 'force_delete',
    ],
    
    /*
     * The package prefix that is being used for package permissions.
     */
    'package_prefix' => 'package',
    
    /*
     * The application prefix that is being used for application permissions.
     */
    'application_prefix' => 'app',
];

Usage

Here's an example in a configuration file containing all permissions that the system holds to sync them on deployment (through a seeder probably).

<?php

use App\Models\Activity;
use App\Models\Customer;
use App\Models\User;
use Rickgoemans\LaravelPermissionService\Services\PermissionService;

return [
    'all' => [
        PermissionService::viewPermission(Activity::class),
        ...PermissionService::crudPermissions(User::class),
        ...PermissionService::crudPermissions(Customer::class, true, true),
        ...PermissionService::packagePermission('nova'),
        ...PermissionService::packagePermission('admin_panel'),
    ],
];

Here's an example of how this can be used in a policy.

<?php

namespace App\Policies;

use App\Models\Example;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Illuminate\Auth\Access\Response;

class ExamplePolicy extends Controller {
    use HandlesAuthorization;
    
    public function viewAny(User $auth): Response|bool
    {
        return $auth->can(PermissionService::viewPermission(Example::class));
    }

    public function view(User $auth, Example $example): Response|bool
    {
        return $auth->can(PermissionService::viewPermission(Example::class));
    }

    public function create(User $auth): Response|bool
    {
        return $auth->can(PermissionService::createPermission(Example::class));
    }

    public function update(User $auth, Example $example): Response|bool
    {
        return $auth->can(PermissionService::updatePermission(Example::class));
    }

    public function delete(User $auth, Example $example): Response|bool
    {
        return $auth->can(PermissionService::deletePermission(Example::class));
    }

    public function restore(User $auth, Example $example): Response|bool
    {
        return $auth->can(PermissionService::restorePermission(Example::class));
    }

    public function forceDelete(User $auth, Example $example): Response|bool
    {
        return $auth->can(PermissionService::forceDeletePermission(Example::class));
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固