Fix for getting book items

This commit is contained in:
Dan Brown 2015-07-30 23:18:48 +01:00
parent 1e2f5ded38
commit b506beac64
2 changed files with 9 additions and 4 deletions

View File

@ -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');
}
}

View File

@ -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();
}