PHP code example of holoultek / laravel-capabilities

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

    

holoultek / laravel-capabilities example snippets




return [
    'ControllerNameWithoutControllerWord' => [
        'capability name' => ['methods', 'as', 'array'],
    ],
];

'Dashboard' => [
    'show dashboard' => ['show'],
],



return [
    'admin' => [
       'show dashboard'
    ],
];

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware('auth', 'capability');

Route::middleware(['auth', 'capability'])->group(function () {
    Route::get('dashboard', [DashboardController::class, 'show'])->name('dashboard');
});

$auth->capabilityAttach('Capability Name');

$auth->capabilityDetach('Capability Name');

// or in short

$auth->ca('Capability Name');

$auth->cd('Capability Name');

$auth->roleAttach('Role Name');

$auth->roleDetach('Role Name');

// or in short

$auth->ra('Role Name');

$auth->rd('Role Name');

$auth->hasCapability('Capability Name');

$auth->hasRole('Role Name');

// or in short

$auth->hc('Capability Name');

$auth->hr('Role Name');

php artisan vendor:publish --tag=laravel-capabilities-migrations

php artisan migrate

php artisan vendor:publish --tag=laravel-capabilities-config

php artisan make:capabilities
php artisan make:roles