|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Equipment; |
|
4
|
|
|
|
|
5
|
|
|
use App\Events\Equipment\EquipmentCategoryCreatedEvent; |
|
6
|
|
|
use App\Events\Equipment\EquipmentCategoryDeletedEvent; |
|
7
|
|
|
use App\Events\Equipment\EquipmentCategoryUpdatedEvent; |
|
8
|
|
|
use App\Http\Controllers\Controller; |
|
9
|
|
|
use App\Http\Requests\Equipment\EquipmentCategoryRequest; |
|
10
|
|
|
use App\Models\EquipmentCategory; |
|
11
|
|
|
use Inertia\Inertia; |
|
12
|
|
|
|
|
13
|
|
|
class EquipmentCategoryController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Show the form for creating a new Equipment Category |
|
17
|
|
|
*/ |
|
18
|
|
|
public function create() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->authorize('create', EquipmentCategory::class); |
|
21
|
|
|
|
|
22
|
|
|
return Inertia::render('EquipmentCategory/Create'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Store a newly created Equipment Category |
|
27
|
|
|
*/ |
|
28
|
|
|
public function store(EquipmentCategoryRequest $request) |
|
29
|
|
|
{ |
|
30
|
|
|
$newCat = EquipmentCategory::create($request->only('name')); |
|
31
|
|
|
|
|
32
|
|
|
event(new EquipmentCategoryCreatedEvent($newCat)); |
|
33
|
|
|
return redirect(route('equipment.index'))->with([ |
|
34
|
|
|
'message' => 'New Category Created', |
|
35
|
|
|
'type' => 'success', |
|
36
|
|
|
]); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Show the form for editing the Category Name |
|
41
|
|
|
*/ |
|
42
|
|
|
public function edit($id) |
|
43
|
|
|
{ |
|
44
|
|
|
$cat = EquipmentCategory::findOrFail($id); |
|
45
|
|
|
$this->authorize('update', $cat); |
|
46
|
|
|
|
|
47
|
|
|
return Inertia::render('EquipmentCategory/Edit', [ |
|
48
|
|
|
'category' => $cat, |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Update the Equipment Category Name |
|
54
|
|
|
*/ |
|
55
|
|
|
public function update(EquipmentCategoryRequest $request, $id) |
|
56
|
|
|
{ |
|
57
|
|
|
$cat = EquipmentCategory::find($id); |
|
58
|
|
|
$cat->update($request->only('name')); |
|
59
|
|
|
|
|
60
|
|
|
event(new EquipmentCategoryUpdatedEvent($cat)); |
|
|
|
|
|
|
61
|
|
|
return redirect(route('equipment.index'))->with([ |
|
62
|
|
|
'message' => 'Category Updated', |
|
63
|
|
|
'type' => 'success', |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Remove the Equipment Category |
|
69
|
|
|
*/ |
|
70
|
|
|
public function destroy($id) |
|
71
|
|
|
{ |
|
72
|
|
|
$cat = EquipmentCategory::find($id); |
|
73
|
|
|
$this->authorize('delete', $cat); |
|
74
|
|
|
$cat->delete(); |
|
75
|
|
|
|
|
76
|
|
|
event(new EquipmentCategoryDeletedEvent($cat)); |
|
|
|
|
|
|
77
|
|
|
return back()->with([ |
|
78
|
|
|
'message' => 'Equipment Category Deleted', |
|
79
|
|
|
'type' => 'danger', |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|