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/ */
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware('auth', 'capabilities-context');
if (UserContext::hasCapability('show dashboard')) {
// User can see the dashboard
}
if (UserContext::hasRole('admin')) {
// User has the admin role
}
if (UserContext::hasRole(['admin', 'editor'])) {
// User is an admin OR an editor
}
if (UserContext::isChief()) {
// User has all capabilities
}
$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');