3 namespace Oxbow\Http\Controllers;
5 use Illuminate\Http\Request;
7 use Oxbow\Http\Requests;
8 use Oxbow\Http\Controllers\Controller;
9 use Oxbow\Repos\BookRepo;
10 use Oxbow\Repos\ChapterRepo;
12 class ChapterController extends Controller
16 protected $chapterRepo;
19 * ChapterController constructor.
23 public function __construct(BookRepo $bookRepo,ChapterRepo $chapterRepo)
25 $this->bookRepo = $bookRepo;
26 $this->chapterRepo = $chapterRepo;
31 * Display a listing of the resource.
35 public function index()
41 * Show the form for creating a new resource.
46 public function create($bookSlug)
48 $book = $this->bookRepo->getBySlug($bookSlug);
49 return view('chapters/create', ['book' => $book]);
53 * Store a newly created resource in storage.
56 * @param Request $request
59 public function store($bookSlug, Request $request)
61 $this->validate($request, [
62 'name' => 'required|string|max:255'
65 $book = $this->bookRepo->getBySlug($bookSlug);
66 $chapter = $this->chapterRepo->newFromInput($request->all());
67 $chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id);
68 $book->chapters()->save($chapter);
69 return redirect($book->getUrl());
73 * Display the specified resource.
78 public function show($id)
84 * Show the form for editing the specified resource.
89 public function edit($id)
95 * Update the specified resource in storage.
97 * @param Request $request
101 public function update(Request $request, $id)
107 * Remove the specified resource from storage.
112 public function destroy($id)