-
- /**
- * Query the references for the given entities.
- * Loads the commonly required relations while taking permissions into account.
- */
- protected function getEntityReferences(Entity $entity): Collection
- {
- $baseQuery = $entity->referencesTo()
- ->where('from_type', '=', (new Page())->getMorphClass())
- ->with([
- 'from' => fn(Relation $query) => $query->select(Page::$listAttributes),
- 'from.book' => fn(Relation $query) => $query->scopes('visible'),
- 'from.chapter' => fn(Relation $query) => $query->scopes('visible')
- ]);
-
- $references = $this->permissions->restrictEntityRelationQuery(
- $baseQuery,
- 'references',
- 'from_id',
- 'from_type'
- )->get();
-
- return $references;
- }