Skip to content

KosmosKosmos/nova-permission-tool

This branch is 3 commits ahead of DigitalCloud/nova-permission-tool:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1245ca5 · Apr 30, 2023

History

21 Commits
Dec 17, 2018
Dec 17, 2018
Dec 17, 2018
Apr 21, 2019
Dec 17, 2018
Feb 6, 2019
Apr 30, 2023
Dec 17, 2018
Dec 17, 2018

Repository files navigation

Nova Permission Tool.

This tool allows you to create and manage rules and permissions for nova resources. After installation, the default nova resource permissions will be generated for all available resources and resource actions.

Requirements & Dependencies

This tool uses Spatie Permission package.

Installation

You can install the package via composer:

composer require digitalcloud/nova-permission-tool

You can publish the migration with:

php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider" --tag="migrations"

After the migration has been published you can create the role- and permission-tables by running the migrations:

php artisan migrate

Usage

You must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider, in app/Providers/NovaServiceProvider.php.

use DigitalCloud\PermissionTool\PermissionTool;
// ....

public function tools()
{
    return [
        // ...
        new PermissionTool(),
        // ...
    ];
}

To allow the tool to generate permissions actions, you need to se the name of the action. Actions with no names will not be generated automatically.

<?php

namespace App\Nova\Actions;

use Laravel\Nova\Actions\Action;

class YourAction extends Action {
    
    // ...

    public $name = 'send email';
    
    // ...

}

and then in the resource you can authorize the action:

<?php

namespace App\Nova;

use App\Nova\Actions\YourAction;
use Illuminate\Support\Facades\Gate;
use Illuminate\Http\Request;


class Quotation extends Resource {
    
    // ...
    
    public function actions(Request $request) {
        return [
            (new YourAction())->canSee(function ($request) {
                return Gate::check('send email'); // the same name of the action
            })->canRun(function ($request) {
                return Gate::check('send email'); // the same name of the action
            })
        ];
    }
    
    // ...
}

Images

per

About

Nova Permissions tool based on spatie permissions

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 71.9%
  • Vue 20.8%
  • Blade 5.5%
  • JavaScript 1.8%