First setup: module registry, switchable modules, permissions

This commit is contained in:
Matthijs Iriks committed 2026-12-04 01:18:14 +01:00
commit 936c794597
52 files changed
+1304

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
<?php
namespace IriksIT\Manager\Concerns;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use IriksIT\Manager\Models\Group;
/**
* Put this on the User model of the host app. Needs the Users module (its migration
* adds `manager_super_admin` to the users table and creates the groups).
*
* A super admin may do everything. Everyone else may do what any of their groups may do.
*/
trait HasManagerAccess
{
public function managerGroups(): BelongsToMany
{
return $this->belongsToMany(Group::class, config('manager.table_prefix').'group_user', 'user_id', 'group_id');
}
public function isManagerSuperAdmin(): bool
{
return (bool) $this->manager_super_admin;
}
public function hasManagerPermission(string $permission): bool
{
if ($this->isManagerSuperAdmin()) {
return true;
}
return $this->managerGroups->contains(fn (Group $group) => in_array($permission, $group->permissions ?? [], true));
}
}