+ /**
+ * Show the form for creating a new chapter.
+ */
+ public function create(string $bookSlug)
+ {
+ $book = Book::visible()->where('slug', '=', $bookSlug)->firstOrFail();
+ $this->checkOwnablePermission('chapter-create', $book);
+
+ $this->setPageTitle(trans('entities.chapters_create'));
+
+ return view('chapters.create', ['book' => $book, 'current' => $book]);
+ }
+
+ /**
+ * Store a newly created chapter in storage.
+ *
+ * @throws ValidationException
+ */
+ public function store(Request $request, string $bookSlug)
+ {
+ $this->validate($request, [
+ 'name' => ['required', 'string', 'max:255'],
+ ]);
+
+ $book = Book::visible()->where('slug', '=', $bookSlug)->firstOrFail();
+ $this->checkOwnablePermission('chapter-create', $book);
+
+ $chapter = $this->chapterRepo->create($request->all(), $book);
+
+ return redirect($chapter->getUrl());
+ }
+
+ /**
+ * Display the specified chapter.
+ */
+ public function show(string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+ $this->checkOwnablePermission('chapter-view', $chapter);
+
+ $sidebarTree = (new BookContents($chapter->book))->getTree();
+ $pages = $chapter->getVisiblePages();
+ $nextPreviousLocator = new NextPreviousContentLocator($chapter, $sidebarTree);
+ View::incrementFor($chapter);
+
+ $this->setPageTitle($chapter->getShortName());
+
+ return view('chapters.show', [
+ 'book' => $chapter->book,
+ 'chapter' => $chapter,
+ 'current' => $chapter,
+ 'sidebarTree' => $sidebarTree,
+ 'pages' => $pages,
+ 'next' => $nextPreviousLocator->getNext(),
+ 'previous' => $nextPreviousLocator->getPrevious(),
+ ]);
+ }
+
+ /**
+ * Show the form for editing the specified chapter.
+ */
+ public function edit(string $bookSlug, string $chapterSlug)
+ {
+ $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+ $this->checkOwnablePermission('chapter-update', $chapter);
+
+ $this->setPageTitle(trans('entities.chapters_edit_named', ['chapterName' => $chapter->getShortName()]));
+
+ return view('chapters.edit', ['book' => $chapter->book, 'chapter' => $chapter, 'current' => $chapter]);
+ }