1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Added page editing

This commit is contained in:
Dan Brown
2015-07-12 21:31:15 +01:00
parent eaa1765c7a
commit 3c7bd297ea
19 changed files with 252 additions and 23 deletions

View File

@ -6,14 +6,17 @@ class BookRepo
{
protected $book;
protected $pageRepo;
/**
* BookRepo constructor.
* @param $book
* @param Book $book
* @param PageRepo $pageRepo
*/
public function __construct(Book $book)
public function __construct(Book $book, PageRepo $pageRepo)
{
$this->book = $book;
$this->pageRepo = $pageRepo;
}
public function getById($id)
@ -44,6 +47,9 @@ class BookRepo
public function destroyById($id)
{
$book = $this->getById($id);
foreach($book->pages as $page) {
$this->pageRepo->destroyById($page->id);
}
$book->delete();
}

52
app/Repos/PageRepo.php Normal file
View File

@ -0,0 +1,52 @@
<?php namespace Oxbow\Repos;
use Illuminate\Support\Str;
use Oxbow\Page;
class PageRepo
{
protected $page;
/**
* PageRepo constructor.
* @param $page
*/
public function __construct(Page $page)
{
$this->page = $page;
}
public function getById($id)
{
return $this->page->findOrFail($id);
}
public function getAll()
{
return $this->page->all();
}
public function getBySlug($slug)
{
return $this->page->where('slug', '=', $slug)->first();
}
public function newFromInput($input)
{
$page = $this->page->fill($input);
return $page;
}
public function countBySlug($slug, $bookId)
{
return $this->page->where('slug', '=', $slug)->where('book_id', '=', $bookId)->count();
}
public function destroyById($id)
{
$page = $this->getById($id);
$page->delete();
}
}