1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Domains\Equipment\GetCategory; |
6
|
|
|
use App\Domains\Equipment\SetCategory; |
7
|
|
|
use App\Http\Controllers\Controller; |
8
|
|
|
use App\Http\Requests\Equipment\CategoryRequest; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
|
11
|
|
|
use Illuminate\Support\Facades\Auth; |
12
|
|
|
use Illuminate\Support\Facades\Log; |
13
|
|
|
|
14
|
|
|
class EquipmentCategoriesController extends Controller |
15
|
|
|
{ |
16
|
|
|
// Show for to creat a new equipment category |
17
|
2 |
|
public function create() |
18
|
|
|
{ |
19
|
2 |
|
return view('admin.equipment.editCategory', [ |
20
|
2 |
|
'data' => null, |
21
|
|
|
]); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// Store the new equipment category |
25
|
2 |
|
public function store(CategoryRequest $request) |
26
|
|
|
{ |
27
|
2 |
|
(new SetCategory)->createCategory($request); |
28
|
2 |
|
Log::notice('New Equipment Category created by '.Auth::user()->full_name.'. Data - ', $request->toArray()); |
29
|
2 |
|
return response()->json(['success' => true]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Edit an existing category |
33
|
2 |
|
public function edit($id) |
34
|
|
|
{ |
35
|
2 |
|
return view('admin.equipment.editCategory', [ |
36
|
2 |
|
'data' => (new GetCategory)->getCategoryData($id), |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// Update an existing category |
41
|
2 |
|
public function update(CategoryRequest $request, $id) |
42
|
|
|
{ |
43
|
2 |
|
(new SetCategory)->updateCategory($request, $id); |
44
|
2 |
|
Log::notice('Category ID '.$id.' - '.$request->name.' has been updated by '.Auth::user()->full_name); |
45
|
|
|
|
46
|
2 |
|
return response()->json(['success' => true]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// Delete an equipment category - note: this will fail if equipment is assigned to the category |
50
|
4 |
|
public function destroy($id) |
51
|
|
|
{ |
52
|
4 |
|
$res = (new SetCategory)->deleteCategory($id); |
53
|
4 |
|
if($res) |
54
|
|
|
{ |
55
|
2 |
|
Log::notice('Equipment Category ID '.$id.' has been deleted by '.Auth::user()->full_name); |
56
|
|
|
} |
57
|
|
|
|
58
|
4 |
|
return response()->json(['success' => $res]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|