Files
mareike/app/Domains/Admin/Repositories/AdminParentGroupRepository.php
T
2026-09-29 14:35:33 +02:00

33 lines
938 B
PHP

<?php
namespace App\Domains\Admin\Repositories;
use App\Models\ParentGroup;
use Illuminate\Database\Eloquent\Collection;
class AdminParentGroupRepository
{
/** Alle Parent Groups, alphabetisch mit „Ohne Zuordnung" am Ende, mit der Zahl zugeordneter Mandanten. */
public function all(): Collection
{
return ParentGroup::withCount('tenants')
->ordered()
->get();
}
public function findById(int $id): ?ParentGroup
{
return ParentGroup::find($id);
}
/**
* Ob die Parent Group noch verwendet wird -- von einem Mandanten oder von einer Anmeldung. Anmeldungen sind
* mandantengebunden; gezählt wird hier bewusst über alle Mandanten hinweg.
*/
public function isInUse(ParentGroup $parentGroup): bool
{
return $parentGroup->tenants()->exists()
|| $parentGroup->eventParticipants()->withoutGlobalScopes()->exists();
}
}