3 namespace BookStack\Entities\Models;
5 use BookStack\References\ReferenceUpdater;
6 use Illuminate\Database\Eloquent\Builder;
7 use Illuminate\Database\Eloquent\Relations\BelongsTo;
12 * @property int $book_id
13 * @property int $priority
14 * @property string $book_slug
15 * @property Book $book
17 abstract class BookChild extends Entity
20 * Get the book this page sits in.
22 public function book(): BelongsTo
24 return $this->belongsTo(Book::class)->withTrashed();
28 * Change the book that this entity belongs to.
30 public function changeBook(int $newBookId): Entity
32 $oldUrl = $this->getUrl();
33 $this->book_id = $newBookId;
38 if ($oldUrl !== $this->getUrl()) {
39 app()->make(ReferenceUpdater::class)->updateEntityReferences($this, $oldUrl);
42 // Update all child pages if a chapter
43 if ($this instanceof Chapter) {
44 foreach ($this->pages()->withTrashed()->get() as $page) {
45 $page->changeBook($newBookId);