PHP code example of salvatorecervone / rolepermissionmanager

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

    

salvatorecervone / rolepermissionmanager example snippets


// ❌ Hardcoded permissions in code
Route::delete('/invoices/{id}', [InvoiceController::class, 'destroy'])
    ->middleware('permission:delete-invoices');

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use SalvatoreCervone\RolePermissionManager\Traits\HasAcl;

class User extends Authenticatable
{
    use HasAcl;
}

'user_models' => [
    'users' => [
        'label'             => 'Users',
        'model'             => App\Models\User::class,
        'searchable_fields' => ['name', 'email'],
        'display_field'     => ['name', 'cognome'],
        'secondary_field'   => 'email',
    ],
    'admins' => [
        'label'             => 'Administrators',
        'model'             => App\Models\Admin::class,
        'searchable_fields' => ['nome', 'cognome', 'email'],
        'display_field'     => ['nome', 'cognome'],
        'secondary_field'   => 'email',
    ],
],

use SalvatoreCervone\RolePermissionManager\Services\AclRegistry;

class CorsoController extends Controller
{
    public function esportaAnagrafica()
    {
        // 1. One line: auto-detects 'CorsoController@esportaAnagrafica'
        AclRegistry::protect();

        // Or specify an explicit alias and optional custom user-facing message:
        // AclRegistry::protect('anagrafica.export', 'Accesso non consentito alla stampa anagrafica.');

        // Business logic runs ONLY if authorized...
    }
}

return [

    // User Model & Search Configuration
    'users' => [
        'table'             => 'users',
        'searchable_fields' => ['name', 'cognome', 'email'],
        
        // Single column or array of columns concatenated with space:
        'display_field'     => ['name', 'cognome'],           // e.g. "Mario Rossi"
        'secondary_field'   => ['matricola', 'email'],        // e.g. "MAT12345 [email protected]"
        'per_page'          => 25,
    ],

    // Super Admin Settings & Bypass
    'super_admin' => [
        'role'       => 'super-admin', // Role slug or null to disable
        'all_access' => true,          // true / 'all' for full bypass, false/null to , 'auth'],
        'page_title' => 'ACL Manager',
        'per_page'   => 25,
    ],

];
bash
php artisan vendor:publish --provider="SalvatoreCervone\RolePermissionManager\RolePermissionManagerServiceProvider"
bash
php artisan migrate
bash
php artisan acl:sync --notify