BookStack\Http\Controllers\ChapterController::move PHP Method

move() public method

Perform the move action for a chapter.
public move ( $bookSlug, $chapterSlug, Illuminate\Http\Request $request ) : mixed
$bookSlug
$chapterSlug
$request Illuminate\Http\Request
return mixed
    public function move($bookSlug, $chapterSlug, Request $request)
    {
        $book = $this->bookRepo->getBySlug($bookSlug);
        $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
        $this->checkOwnablePermission('chapter-update', $chapter);
        $entitySelection = $request->get('entity_selection', null);
        if ($entitySelection === null || $entitySelection === '') {
            return redirect($chapter->getUrl());
        }
        $stringExploded = explode(':', $entitySelection);
        $entityType = $stringExploded[0];
        $entityId = intval($stringExploded[1]);
        $parent = false;
        if ($entityType == 'book') {
            $parent = $this->bookRepo->getById($entityId);
        }
        if ($parent === false || $parent === null) {
            session()->flash('The selected Book was not found');
            return redirect()->back();
        }
        $this->chapterRepo->changeBook($parent->id, $chapter, true);
        Activity::add($chapter, 'chapter_move', $chapter->book->id);
        session()->flash('success', sprintf('Chapter moved to "%s"', $parent->name));
        return redirect($chapter->getUrl());
    }