diff --git a/app/Book.php b/app/Book.php index ccf02e4f3..35df08338 100644 --- a/app/Book.php +++ b/app/Book.php @@ -33,8 +33,10 @@ class Book extends Model { $pages = $this->pages()->where('chapter_id', '=', 0)->get(); $chapters = $this->chapters()->get(); - $children = $pages->merge($chapters); - return $children->sortBy('priority'); + foreach($chapters as $chapter) { + $pages->push($chapter); + } + return $pages->sortBy('priority'); } } diff --git a/app/Repos/BookRepo.php b/app/Repos/BookRepo.php index b98ed9aba..5a772539f 100644 --- a/app/Repos/BookRepo.php +++ b/app/Repos/BookRepo.php @@ -47,8 +47,11 @@ class BookRepo public function destroyBySlug($bookSlug) { $book = $this->getBySlug($bookSlug); - foreach($book->children() as $child) { - $child->delete(); + foreach($book->pages as $page) { + $page->delete(); + } + foreach($book->chapters as $chapter) { + $chapter->delete(); } $book->delete(); }