Spatie Permission Adapter for Cbox ID
Quickstart
Quickstart
Three steps take an app that already runs spatie/laravel-permission to one where Cbox ID mints tokens from your Spatie roles.
1. Install
composer require cboxdk/laravel-id-spatie
Both this package and Cbox ID auto-register.
2. Select the external driver and configure the adapter
// config/cbox-id.php
'access_control' => ['driver' => 'external'],
Publish and set the adapter config:
php artisan vendor:publish --tag=id-spatie-config
// config/id-spatie.php
return [
'user_model' => App\Models\User::class,
'teams' => false, // true to scope roles per organization via Spatie teams
'guard' => 'web',
];
3. Declare the contract on your user model
The model that already uses Spatie's HasRoles trait adds one interface:
use Cbox\Id\Spatie\Contracts\SpatieSubject;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements SpatieSubject
{
use HasRoles;
}
That is all. The platform now resolves every authorization check and stamps every token from Spatie:
use Cbox\Id\AccessControl\Contracts\AccessChecker;
app(AccessChecker::class)->can($user->id, 'posts.edit', $organizationId); // ← Spatie
Next: how it works and installation details.