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:
@ -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
52
app/Repos/PageRepo.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user