PHP code example of luilliarcec / filament-shield

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

    

luilliarcec / filament-shield example snippets




return [
    /*
     * Predefined resource to handle system roles, you can replace it with your own.
     */
    'resources' => [
        'role' => Resources\RoleResource::class
    ],

    /*
     * System roles, enable them to your liking.
     */
    'roles' => [
        'super_admin' => [
            'enabled' => true,
            'role_name' => 'super_admin',
        ],

        'filament_user' => [
            'enabled' => false,
            'role_name' => 'filament_user',
        ],
    ],

    /**
     * Default global permissions are defined here, however you are free to change
     * them from your filament `resource`, `page` or `widget`.
     */
    'suffixes' => [
        'resource' => [
            'view_any',
            'view',
            'create',
            'update',
            'delete',
            'delete_any',
            'restore',
        ],
        'page' => 'view',
        'widget' => 'view',
    ],

    /**
     * The package uses a wildcard format with "-" instead of dots, due to the representation of objects
     * that livewire gives you, when using this format, the package discovers the segments
     * from the namespace of the filament `resource`, `page` or `widget`.
     *
     * {module}.{resource}.{action} => {module}-{resource}-{action}
     *
     * Filament
     *   - Resources
     *     - Security
     *       - RoleResource.php
     *
     * App\Filament\Resources\Security\RoleResource
     *
     * Ex.: security-role-view_any
     */

    'dont_modules' => [
        'src',
        'domain',
        'manages',
        'app',
        'filament',
        'resources',
        'pages',
        'widgets',
    ]
];

use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles;

    // ...
}

use Filament\Resources\Resource;
use Luilliarcec\FilamentShield\Contracts\HasPermissions;

class RoleResource extends Resource implements HasPermissions
{
    // 
}

use Filament\Resources\Resource;
use Luilliarcec\FilamentShield\Contracts\HasPermissions
use Luilliarcec\FilamentShield\Concerns\HasResourcePermissions;

class RoleResource extends Resource implements HasPermissions
{
    use HasResourcePermissions;
}

use Filament\Resources\Resource;
use Luilliarcec\FilamentShield\Contracts\HasPermissions;
use Luilliarcec\FilamentShield\Concerns\HasResourcePermissions;

class RoleResource extends Resource implements HasPermissions
{
    use HasResourcePermissions;
    
    //

    public static function permissions(): array|string
    {
        return [
            'view_any',
            'export'
        ];
    }
}
bash
php artisan vendor:publish --tag="filament-shield-config"
bash
php artisan shield:generate