class BooksController extends Controller { public function index() { abort_unless(\Gate::allows('book_access'), 403); $books = Book::all(); return view('admin.books.index', compact('books')); } public function create() { abort_unless(\Gate::allows('book_create'), 403); return view('admin.books.create'); } public function store(StoreBookRequest $request) { abort_unless(\Gate::allows('book_create'), 403); $book = Book::create($request->all()); return redirect()->route('admin.books.index'); } public function edit(Book $book) { abort_unless(\Gate::allows('book_edit'), 403); return view('admin.books.edit', compact('book')); } public function update(UpdateBookRequest $request, Book $book) { abort_unless(\Gate::allows('book_edit'), 403); $book->update($request->all()); return redirect()->route('admin.books.index'); } public function show(Book $book) { abort_unless(\Gate::allows('book_show'), 403); return view('admin.books.show', compact('book')); } public function destroy(Book $book) { abort_unless(\Gate::allows('book_delete'), 403); $book->delete(); return back(); } }On top of that, we add check in Form Request classes, see example:
class StoreBookRequest extends FormRequest { public function authorize() { return \Gate::allows('book_create'); } }
If you can't find what you're looking for, use live-chat on bottom-right or email us info@laraveldaily.com