|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers\Admin; |
| 4 | + |
| 5 | +use App\ExpenseCategory; |
| 6 | +use App\Http\Controllers\Controller; |
| 7 | +use App\Http\Requests\MassDestroyExpenseCategoryRequest; |
| 8 | +use App\Http\Requests\StoreExpenseCategoryRequest; |
| 9 | +use App\Http\Requests\UpdateExpenseCategoryRequest; |
| 10 | +use Gate; |
| 11 | +use Illuminate\Http\Request; |
| 12 | +use Symfony\Component\HttpFoundation\Response; |
| 13 | + |
| 14 | +class ExpenseCategoryController extends Controller |
| 15 | +{ |
| 16 | + public function index() |
| 17 | + { |
| 18 | + abort_if(Gate::denies('expense_category_access'), Response::HTTP_FORBIDDEN, '403 Forbidden'); |
| 19 | + |
| 20 | + $expenseCategories = ExpenseCategory::all(); |
| 21 | + |
| 22 | + return view('admin.expenseCategories.index', compact('expenseCategories')); |
| 23 | + } |
| 24 | + |
| 25 | + public function create() |
| 26 | + { |
| 27 | + abort_if(Gate::denies('expense_category_create'), Response::HTTP_FORBIDDEN, '403 Forbidden'); |
| 28 | + |
| 29 | + return view('admin.expenseCategories.create'); |
| 30 | + } |
| 31 | + |
| 32 | + public function store(StoreExpenseCategoryRequest $request) |
| 33 | + { |
| 34 | + $expenseCategory = ExpenseCategory::create($request->all()); |
| 35 | + |
| 36 | + return redirect()->route('admin.expense-categories.index'); |
| 37 | + } |
| 38 | + |
| 39 | + public function edit(ExpenseCategory $expenseCategory) |
| 40 | + { |
| 41 | + abort_if(Gate::denies('expense_category_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden'); |
| 42 | + |
| 43 | + $expenseCategory->load('created_by'); |
| 44 | + |
| 45 | + return view('admin.expenseCategories.edit', compact('expenseCategory')); |
| 46 | + } |
| 47 | + |
| 48 | + public function update(UpdateExpenseCategoryRequest $request, ExpenseCategory $expenseCategory) |
| 49 | + { |
| 50 | + $expenseCategory->update($request->all()); |
| 51 | + |
| 52 | + return redirect()->route('admin.expense-categories.index'); |
| 53 | + } |
| 54 | + |
| 55 | + public function show(ExpenseCategory $expenseCategory) |
| 56 | + { |
| 57 | + abort_if(Gate::denies('expense_category_show'), Response::HTTP_FORBIDDEN, '403 Forbidden'); |
| 58 | + |
| 59 | + $expenseCategory->load('created_by'); |
| 60 | + |
| 61 | + return view('admin.expenseCategories.show', compact('expenseCategory')); |
| 62 | + } |
| 63 | + |
| 64 | + public function destroy(ExpenseCategory $expenseCategory) |
| 65 | + { |
| 66 | + abort_if(Gate::denies('expense_category_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden'); |
| 67 | + |
| 68 | + $expenseCategory->delete(); |
| 69 | + |
| 70 | + return back(); |
| 71 | + } |
| 72 | + |
| 73 | + public function massDestroy(MassDestroyExpenseCategoryRequest $request) |
| 74 | + { |
| 75 | + ExpenseCategory::whereIn('id', request('ids'))->delete(); |
| 76 | + |
| 77 | + return response(null, Response::HTTP_NO_CONTENT); |
| 78 | + } |
| 79 | +} |
0 commit comments