queryReferencesToEntity($entity)->get(); $this->mixedEntityListLoader->loadIntoRelations($references->all(), 'from', true); return $references; } /** * Returns the count of references pointing to the given entity. * Takes permissions into account. */ public function getReferenceCountToEntity(Entity $entity): int { return $this->queryReferencesToEntity($entity)->count(); } protected function queryReferencesToEntity(Entity $entity): Builder { $baseQuery = Reference::query() ->where('to_type', '=', $entity->getMorphClass()) ->where('to_id', '=', $entity->id); return $this->permissions->restrictEntityRelationQuery( $baseQuery, 'references', 'from_id', 'from_type' ); } }