]> BookStack Code Mirror - bookstack/blob - app/Repos/BookRepo.php
Initial commit
[bookstack] / app / Repos / BookRepo.php
1 <?php namespace Oxbow\Repos;
2
3 use Oxbow\Book;
4
5 class BookRepo
6 {
7
8     protected $book;
9
10     /**
11      * BookRepo constructor.
12      * @param $book
13      */
14     public function __construct(Book $book)
15     {
16         $this->book = $book;
17     }
18
19     public function getById($id)
20     {
21         return $this->book->findOrFail($id);
22     }
23
24     public function getAll()
25     {
26         return $this->book->all();
27     }
28
29     public function getBySlug($slug)
30     {
31         return $this->book->where('slug', '=', $slug)->first();
32     }
33
34     public function newFromInput($input)
35     {
36         return $this->book->fill($input);
37     }
38
39     public function countBySlug($slug)
40     {
41         return $this->book->where('slug', '=', $slug)->count();
42     }
43
44     public function destroyById($id)
45     {
46         $book = $this->getById($id);
47         $book->delete();
48     }
49
50 }