1. Go to this page and download the library: Download kirchdev/laravel-pbac 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/ */
use KirchDev\Pbac\Facades\Pbac;
Pbac::withOrganisation($organisation->id, function () use ($user) {
$user->can('members.invite'); // checked against org-bound roles
$user->can('billing.view'); // …same scope
});
// Global checks — no active org
Pbac::withoutOrganisation(fn () => $user->can('admin.impersonate'));
final class TenantRouteResolver implements \KirchDev\Pbac\Contracts\OrganisationResolver
{
public function getOrganisationId(): int|string|null
{
return request()->route('organisation')?->getKey();
}
// …setOrganisationId, clearOrganisationId
}
bash
# Grant a global role
php artisan pbac:role:assign 1 superadmin --global
# Grant an organisation-bound role, looking the target up by email
php artisan pbac:role:assign [email protected] owner --organisation=42 --column=email
# Take it away again
php artisan pbac:role:revoke 1 superadmin --global