public static function table(Table $table): Table
{
$user = auth()->user();
$org_user_id = Cache::remember("user_{$user->id}_can_manage_organisations", now()->addMinutes(10), function () use ($user) {
return $user->managedOrganisations()->pluck('user_id');
});
// Get roles and permissions once
// Cache::forget("user_{$user->id}_permissions");
$canManageOrganisations = Cache::remember("user_{$user->id}_permissions", now()->addMinutes(10), function () use ($user) {
if ($user->hasRole(RoleConstants::SUPER_ADMIN)) {
return true;
}
if ($user->checkPermissionTo('User.view-any')) {
return true;
}
return $user->canManageAnyOrganisations();
});
return $table
->modifyQueryUsing(function ($query) use ($user, $org_user_id) {
if ($user->hasRole(RoleConstants::SUPER_ADMIN)) {
return $query;
}
if ($user->checkPermissionTo('User.view-any')) {
return $query;
}
if ($user->canManageAnyOrganisations()) {
return $query->whereIn('id', $org_user_id);
}
})
public static function table(Table $table): Table
{
$user = auth()->user();
$org_user_id = Cache::remember("user_{$user->id}_can_manage_organisations", now()->addMinutes(10), function () use ($user) {
return $user->managedOrganisations()->pluck('user_id');
});
// Get roles and permissions once
// Cache::forget("user_{$user->id}_permissions");
$canManageOrganisations = Cache::remember("user_{$user->id}_permissions", now()->addMinutes(10), function () use ($user) {
if ($user->hasRole(RoleConstants::SUPER_ADMIN)) {
return true;
}
if ($user->checkPermissionTo('User.view-any')) {
return true;
}
return $user->canManageAnyOrganisations();
});
return $table
->modifyQueryUsing(function ($query) use ($user, $org_user_id) {
if ($user->hasRole(RoleConstants::SUPER_ADMIN)) {
return $query;
}
if ($user->checkPermissionTo('User.view-any')) {
return $query;
}
if ($user->canManageAnyOrganisations()) {
return $query->whereIn('id', $org_user_id);
}
})