PHP code example of yadahan / nova-bouncer

1. Go to this page and download the library: Download yadahan/nova-bouncer 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/ */

    

yadahan / nova-bouncer example snippets


public function tools()
{
    return [
        // ...
        new \Yadahan\BouncerTool\BouncerTool,
    ];
}

use Laravel\Nova\Fields\MorphToMany;
use Laravel\Nova\Fields\Text;

public function fields(Request $request)
{
    return [
        // ...
        MorphToMany::make('Roles', 'roles', 'Yadahan\BouncerTool\Nova\Role')->fields(function () {
            return [
                Text::make('Scope')
                    ->sortable()
                    ->rules('nullable', 'integer'),
            ];
        }),

        MorphToMany::make('Abilities', 'abilities', 'Yadahan\BouncerTool\Nova\Ability')
            ->fields(new \Yadahan\BouncerTool\Nova\PermissionsFields),
    ];
}

'actions' => [
    '*' => 'Manage',
    'viewAny' => 'View Any',
    'view' => 'View',
    'create' => 'Create',
    'update' => 'Update',
    'replicate' => 'Replicate',
    'delete' => 'Delete',
    'restore' => 'Restore',
    'forceDelete' => 'Force Delete',
    'runAction' => 'Run Action',
    'runDestructiveAction' => 'Run Destructive Action',
],

'entities' => [
    'User' => App\Models\User::class,
],

$user = User::find(1);

Bouncer::allow($user)->toManage(\Silber\Bouncer\Database\Role::class);
Bouncer::allow($user)->toManage(\Silber\Bouncer\Database\Ability::class);

// or

$role = Bouncer::role()->create(['name' => 'manage-bouncer']);

Bouncer::allow($role)->toManage(\Silber\Bouncer\Database\Role::class);
Bouncer::allow($role)->toManage(\Silber\Bouncer\Database\Ability::class);

$user->assign($role);