/** * Changes the book relation of this chapter. * @param $bookId * @param Chapter $chapter * @param bool $rebuildPermissions * @return Chapter */ public function changeBook($bookId, Chapter $chapter, $rebuildPermissions = false) { $chapter->book_id = $bookId; // Update related activity foreach ($chapter->activity as $activity) { $activity->book_id = $bookId; $activity->save(); } $chapter->slug = $this->findSuitableSlug($chapter->name, $bookId, $chapter->id); $chapter->save(); // Update all child pages foreach ($chapter->pages as $page) { $this->pageRepo->changeBook($bookId, $page); } // Update permissions if applicable if ($rebuildPermissions) { $chapter->load('book'); $this->permissionService->buildJointPermissionsForEntity($chapter->book); } return $chapter; }
/** * Changes the book relation of this chapter. * @param $bookId * @param Chapter $chapter * @return Chapter */ public function changeBook($bookId, Chapter $chapter) { $chapter->book_id = $bookId; foreach ($chapter->activity as $activity) { $activity->book_id = $bookId; $activity->save(); } $chapter->slug = $this->findSuitableSlug($chapter->name, $bookId, $chapter->id); $chapter->save(); return $chapter; }