Wiring models
composer require langsys/laravel-access-guard Implement the contracts on your own models — Access Guard never assumes your schema.
User (AuthorizableByUser, plus optional Authorizable for super admins):
use Langsys\AccessGuard\Contracts\Authorizable;use Langsys\AccessGuard\Contracts\AuthorizableByUser;use Langsys\AccessGuard\Contracts\GrantsPermissions;
class User extends Authenticatable implements Authorizable, AuthorizableByUser{ public function isSuperAdmin(): bool { return $this->type === UserType::SuperAdmin; }
public function userRoleInEntity(mixed $entity): ?GrantsPermissions { return $this->roleInEntity($entity); // your pivot lookup → a Role }
public function userHasDisabledEntity(mixed $entity): bool { return $this->disabledEntities()->whereKey($entity->getKey())->exists(); }}The role you return implements GrantsPermissions — a single method, hasPermission(string $permission): bool — so the role answers for itself whether it grants a permission. The bundled Role model implements it already.
Entity — mark anything you authorize against with GuardableResource:
use Langsys\AccessGuard\Contracts\GuardableResource;
class Project extends Model implements GuardableResource {}API key (optional, AuthorizableByKey) — see Using with laravel-api-keys.