]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/ChapterController.php
Started working on chapters
[bookstack] / app / Http / Controllers / ChapterController.php
1 <?php
2
3 namespace Oxbow\Http\Controllers;
4
5 use Illuminate\Http\Request;
6
7 use Oxbow\Http\Requests;
8 use Oxbow\Http\Controllers\Controller;
9 use Oxbow\Repos\BookRepo;
10 use Oxbow\Repos\ChapterRepo;
11
12 class ChapterController extends Controller
13 {
14
15     protected $bookRepo;
16     protected $chapterRepo;
17
18     /**
19      * ChapterController constructor.
20      * @param $bookRepo
21      * @param $chapterRepo
22      */
23     public function __construct(BookRepo $bookRepo,ChapterRepo $chapterRepo)
24     {
25         $this->bookRepo = $bookRepo;
26         $this->chapterRepo = $chapterRepo;
27     }
28
29
30     /**
31      * Display a listing of the resource.
32      *
33      * @return Response
34      */
35     public function index()
36     {
37         //
38     }
39
40     /**
41      * Show the form for creating a new resource.
42      *
43      * @param $bookSlug
44      * @return Response
45      */
46     public function create($bookSlug)
47     {
48         $book = $this->bookRepo->getBySlug($bookSlug);
49         return view('chapters/create', ['book' => $book]);
50     }
51
52     /**
53      * Store a newly created resource in storage.
54      *
55      * @param $bookSlug
56      * @param  Request $request
57      * @return Response
58      */
59     public function store($bookSlug, Request $request)
60     {
61         $this->validate($request, [
62             'name' => 'required|string|max:255'
63         ]);
64
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());
70     }
71
72     /**
73      * Display the specified resource.
74      *
75      * @param  int  $id
76      * @return Response
77      */
78     public function show($id)
79     {
80         //
81     }
82
83     /**
84      * Show the form for editing the specified resource.
85      *
86      * @param  int  $id
87      * @return Response
88      */
89     public function edit($id)
90     {
91         //
92     }
93
94     /**
95      * Update the specified resource in storage.
96      *
97      * @param  Request  $request
98      * @param  int  $id
99      * @return Response
100      */
101     public function update(Request $request, $id)
102     {
103         //
104     }
105
106     /**
107      * Remove the specified resource from storage.
108      *
109      * @param  int  $id
110      * @return Response
111      */
112     public function destroy($id)
113     {
114         //
115     }
116 }