PHP code example of elpandape / filament-bouncer

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

    

elpandape / filament-bouncer example snippets


use ElPandaPe\FilamentBouncer\Filament\FilamentBouncerPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(FilamentBouncerPlugin::make());
}

Bouncer::tables([
    'roles' => 'bouncer_roles',
    'permissions' => 'bouncer_permissions',
]);

use ElPandaPe\FilamentBouncer\Filament\Widgets\AbilityHealth;

$panel->widgets([
    AbilityHealth::class,
]);

use ElPandaPe\FilamentBouncer\Filament\Concerns\AuthorizesPage;

class Reports extends Page
{
    use AuthorizesPage;
}

'labels' => [
    'actions' => ['viewAny' => 'Browse'],
],

'ownership' => [
    \App\Models\Post::class => 'author_id',
],

Event::listen(function (RoleAssignedEvent $event): void {
    activity()
        ->causedBy($event->causer)
        ->performedOn($event->authority)
        ->event('assigned the role')
        ->log($event->role);
});

$changes = [];

Event::listen(AbilityStanceChangedEvent::class, function (AbilityStanceChangedEvent $event) use (&$changes): void {
    $changes[] = $event;
});

Event::listen(AbilityStancesSavedEvent::class, function (AbilityStancesSavedEvent $event) use (&$changes): void {
    // every cell of this save has already been heard
    record($event->authority, $changes);
    $changes = [];
});

  Bouncer::ownedVia('*', fn (Model $model, Model $authority): bool => array_key_exists('user_id', $model->getAttributes())
      && $model->getAttribute('user_id') === $authority->getKey());
  
bash
php artisan vendor:publish --tag=filament-bouncer-config
bash
php artisan vendor:publish --tag=bouncer.migrations
php artisan migrate
bash
php artisan filament-bouncer:reconcile
bash
php artisan filament-bouncer:assign owner [email protected]
bash
php artisan filament-bouncer:policy
bash
php artisan filament-bouncer:reconcile --check