Showing
2 changed files
with
9 additions
and
4 deletions
| ... | @@ -33,8 +33,10 @@ class Book extends Model | ... | @@ -33,8 +33,10 @@ class Book extends Model |
| 33 | { | 33 | { |
| 34 | $pages = $this->pages()->where('chapter_id', '=', 0)->get(); | 34 | $pages = $this->pages()->where('chapter_id', '=', 0)->get(); |
| 35 | $chapters = $this->chapters()->get(); | 35 | $chapters = $this->chapters()->get(); |
| 36 | - $children = $pages->merge($chapters); | 36 | + foreach($chapters as $chapter) { |
| 37 | - return $children->sortBy('priority'); | 37 | + $pages->push($chapter); |
| 38 | + } | ||
| 39 | + return $pages->sortBy('priority'); | ||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | } | 42 | } | ... | ... |
| ... | @@ -47,8 +47,11 @@ class BookRepo | ... | @@ -47,8 +47,11 @@ class BookRepo |
| 47 | public function destroyBySlug($bookSlug) | 47 | public function destroyBySlug($bookSlug) |
| 48 | { | 48 | { |
| 49 | $book = $this->getBySlug($bookSlug); | 49 | $book = $this->getBySlug($bookSlug); |
| 50 | - foreach($book->children() as $child) { | 50 | + foreach($book->pages as $page) { |
| 51 | - $child->delete(); | 51 | + $page->delete(); |
| 52 | + } | ||
| 53 | + foreach($book->chapters as $chapter) { | ||
| 54 | + $chapter->delete(); | ||
| 52 | } | 55 | } |
| 53 | $book->delete(); | 56 | $book->delete(); |
| 54 | } | 57 | } | ... | ... |
-
Please register or sign in to post a comment