PHP code example of jeffersonsimaogoncalves / nova-permission

1. Go to this page and download the library: Download jeffersonsimaogoncalves/nova-permission library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeffersonsimaogoncalves / nova-permission example snippets


// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \JeffersonSimaoGoncalves\NovaPermission\NovaPermissionTool::make(),
    ];
}

// in config/nova.php
'middleware' => [
    // ...
    \JeffersonSimaoGoncalves\NovaPermission\ForgetCachedPermissions::class,
],

// ...
use Laravel\Nova\Fields\MorphToMany;

public function fields(Request $request)
{
    return [
        // ...
        MorphToMany::make('Roles', 'roles', \JeffersonSimaoGoncalves\NovaPermission\Nova\Role::class),
        MorphToMany::make('Permissions', 'permissions', \JeffersonSimaoGoncalves\NovaPermission\Nova\Permission::class),
    ];
}

// ...
use JeffersonSimaoGoncalves\NovaPermission\Nova\Fields\PermissionBooleanGroup;
use JeffersonSimaoGoncalves\NovaPermission\Nova\Fields\RoleBooleanGroup;

public function fields(Request $request)
{
    return [
        // ...
        RoleBooleanGroup::make('Roles'),
        PermissionBooleanGroup::make('Permissions'),
    ];
}

// ...
use JeffersonSimaoGoncalves\NovaPermission\Nova\Fields\RoleSelect;

public function fields(Request $request)
{
    return [
        // ...
        RoleSelect::make('Role', 'roles'),
    ];
}

// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \JeffersonSimaoGoncalves\NovaPermission\NovaPermissionTool::make()
            ->roleResource(CustomRole::class)
            ->permissionResource(CustomPermission::class),
    ];
}


// ...
use JeffersonSimaoGoncalves\NovaPermission\Nova\Fields\PermissionBooleanGroup;
use JeffersonSimaoGoncalves\NovaPermission\Nova\Fields\RoleSelect;

public function fields(Request $request)
{
    return [
        // ...
        RoleBooleanGroup::make('Roles', 'roles', null, 'description'),
        PermissionBooleanGroup::make('Permissions', 'permissions', null, 'description'),
        RoleSelect::make('Role', 'roles', null, 'description'),
    ];
}

// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \JeffersonSimaoGoncalves\NovaPermission\NovaPermissionTool::make()
            ->rolePolicy(RolePolicy::class)
            ->permissionPolicy(PermissionPolicy::class),
    ];
}