get($entityType)->visible()->findOrFail($entityId); $entities = []; // Page in chapter if ($entity->isA('page') && $entity->chapter) { $entities = $entity->chapter->getVisiblePages(); } // Page in book or chapter if (($entity->isA('page') && !$entity->chapter) || $entity->isA('chapter')) { $entities = $entity->book->getDirectChildren(); } // Book // Gets just the books in a shelf if shelf is in context if ($entity->isA('book')) { $contextShelf = (new ShelfContext)->getContextualShelfForBook($entity); if ($contextShelf) { $entities = $contextShelf->visibleBooks()->get(); } else { $entities = Book::visible()->get(); } } // Shelve if ($entity->isA('bookshelf')) { $entities = Bookshelf::visible()->get(); } return $entities; } }