public function checkInTeam(User $user, Entity $entity) { $userTeamIdList = $user->getLinkMultipleIdList('teams'); if (!$entity->hasRelation('teams') || !$entity->hasAttribute('teamsIds')) { return false; } $entityTeamIdList = $entity->getLinkMultipleIdList('teams'); if (empty($entityTeamIdList)) { return false; } foreach ($userTeamIdList as $id) { if (in_array($id, $entityTeamIdList)) { return true; } } return false; }