1 <?php namespace Oxbow\Repos;
12 * BookRepo constructor.
14 * @param PageRepo $pageRepo
16 public function __construct(Book $book, PageRepo $pageRepo)
19 $this->pageRepo = $pageRepo;
22 public function getById($id)
24 return $this->book->findOrFail($id);
27 public function getAll()
29 return $this->book->all();
32 public function getBySlug($slug)
34 return $this->book->where('slug', '=', $slug)->first();
37 public function newFromInput($input)
39 return $this->book->fill($input);
42 public function countBySlug($slug)
44 return $this->book->where('slug', '=', $slug)->count();
47 public function destroyById($id)
49 $book = $this->getById($id);
50 foreach($book->pages as $page) {
51 $this->pageRepo->destroyById($page->id);
56 public function getTree($book, $currentPageId = false)
58 $tree = $book->toArray();
59 $tree['pages'] = $this->pageRepo->getTreeByBookId($book->id, $currentPageId);
60 $tree['hasChildren'] = count($tree['pages']) > 0;