public function store(Request $request, $bookSlug, $pageId)
{
$this->validate($request, ['name' => 'required|string|max:255']);
$input = $request->all();
$book = $this->bookRepo->getBySlug($bookSlug);
$draftPage = $this->pageRepo->getById($pageId, true);
$chapterId = intval($draftPage->chapter_id);
$parent = $chapterId !== 0 ? $this->chapterRepo->getById($chapterId) : $book;
$this->checkOwnablePermission('page-create', $parent);
if ($parent->isA('chapter')) {
$input['priority'] = $this->chapterRepo->getNewPriority($parent);
} else {
$input['priority'] = $this->bookRepo->getNewPriority($parent);
}
$page = $this->pageRepo->publishDraft($draftPage, $input);
Activity::add($page, 'page_create', $book->id);
return redirect($page->getUrl());
}