3 namespace Oxbow\Http\Controllers;
5 use Illuminate\Http\Request;
7 use Illuminate\Support\Facades\Auth;
8 use Illuminate\Support\Str;
9 use Oxbow\Http\Requests;
10 use Oxbow\Repos\BookRepo;
11 use Oxbow\Repos\PageRepo;
13 class BookController extends Controller
20 * BookController constructor.
21 * @param BookRepo $bookRepo
22 * @param PageRepo $pageRepo
24 public function __construct(BookRepo $bookRepo, PageRepo $pageRepo)
26 $this->bookRepo = $bookRepo;
27 $this->pageRepo = $pageRepo;
31 * Display a listing of the book.
35 public function index()
37 $books = $this->bookRepo->getAll();
38 return view('books/index', ['books' => $books]);
42 * Show the form for creating a new book.
46 public function create()
48 return view('books/create');
52 * Store a newly created book in storage.
54 * @param Request $request
57 public function store(Request $request)
59 $this->validate($request, [
60 'name' => 'required|string|max:255',
61 'description' => 'string|max:1000'
63 $book = $this->bookRepo->newFromInput($request->all());
64 $book->slug = $this->bookRepo->findSuitableSlug($book->name);
65 $book->created_by = Auth::user()->id;
66 $book->updated_by = Auth::user()->id;
68 return redirect('/books');
72 * Display the specified book.
77 public function show($slug)
79 $book = $this->bookRepo->getBySlug($slug);
80 return view('books/show', ['book' => $book, 'current' => $book]);
84 * Show the form for editing the specified book.
89 public function edit($slug)
91 $book = $this->bookRepo->getBySlug($slug);
92 return view('books/edit', ['book' => $book, 'current' => $book]);
96 * Update the specified book in storage.
98 * @param Request $request
102 public function update(Request $request, $slug)
104 $book = $this->bookRepo->getBySlug($slug);
105 $this->validate($request, [
106 'name' => 'required|string|max:255',
107 'description' => 'string|max:1000'
109 $book->fill($request->all());
110 $book->slug = $this->bookRepo->findSuitableSlug($book->name, $book->id);
111 $book->updated_by = Auth::user()->id;
113 return redirect($book->getUrl());
117 * Shows the page to confirm deletion
119 * @return \Illuminate\View\View
121 public function showDelete($bookSlug)
123 $book = $this->bookRepo->getBySlug($bookSlug);
124 return view('books/delete', ['book' => $book, 'current' => $book]);
128 * Remove the specified book from storage.
133 public function destroy($bookSlug)
135 $this->bookRepo->destroyBySlug($bookSlug);
136 return redirect('/books');