1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Installer; |
4
|
|
|
|
5
|
|
|
use App\SystemCategories; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Validation\Rule; |
8
|
|
|
use Illuminate\Support\Facades\Log; |
9
|
|
|
use Illuminate\Support\Facades\Auth; |
10
|
|
|
use App\Http\Controllers\Controller; |
11
|
|
|
|
12
|
|
|
class CategoriesController extends Controller |
13
|
|
|
{ |
14
|
|
|
public function __construct() |
15
|
|
|
{ |
16
|
|
|
$this->middleware('auth'); |
17
|
|
|
} |
18
|
|
|
// View the list of categories |
19
|
|
|
public function index() |
20
|
|
|
{ |
21
|
|
|
$categories = SystemCategories::all(); |
22
|
|
|
|
23
|
|
|
return view('installer.categoryList', [ |
24
|
|
|
'cats' => $categories |
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
// New category form |
29
|
|
|
public function create() |
30
|
|
|
{ |
31
|
|
|
return view('installer.newCategory'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
// Store the new category form |
35
|
|
|
public function store(Request $request) |
36
|
|
|
{ |
37
|
|
|
$request->validate([ |
38
|
|
|
'name' => 'required|string|unique:system_categories|regex:/^[a-zA-Z0-9_ ]*$/' |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$cat = SystemCategories::create([ |
|
|
|
|
42
|
|
|
'name' => $request->name |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
Log::info('New System Category Created', ['cat_name' => $request->name, 'user_id' => Auth::user()->user_id]); |
46
|
|
|
|
47
|
|
|
Log::info('New System Category - '.$request->name.' created by User ID-'.Auth::user()->user_id); |
48
|
|
|
|
49
|
|
|
return redirect()->back()->with('success', 'Category Successfully Added. <a href="'.route('installer.systems.create').'">Add System</a>'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// Brind up the Edit System F |
53
|
|
|
public function show($id) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
// |
56
|
|
|
echo 'show'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Brind up the Edit Category Form |
60
|
|
|
public function edit($id) |
61
|
|
|
{ |
62
|
|
|
$cat = SystemCategories::find($id); |
63
|
|
|
|
64
|
|
|
if(!$cat) |
65
|
|
|
{ |
66
|
|
|
return response(404); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return view('installer.editCategory', [ |
70
|
|
|
'details' => $cat |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Submit teh Edit Category form |
75
|
|
|
public function update(Request $request, $id) |
76
|
|
|
{ |
77
|
|
|
$request->validate([ |
78
|
|
|
'name' => [ |
79
|
|
|
'required', |
80
|
|
|
'string', |
81
|
|
|
Rule::unique('system_categories')->ignore($id, 'cat_id'), |
82
|
|
|
'regex:/^[a-zA-Z0-9_ ]*$/' |
83
|
|
|
] |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
SystemCategories::find($id)->update([ |
87
|
|
|
'name' => $request->name |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
return redirect()->back()->with('success', 'Category Successfully Modified. <a href="'.route('installer.systems.create').'">Add System</a>'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Remove the specified resource from storage. |
95
|
|
|
* |
96
|
|
|
* @param int $id |
97
|
|
|
* @return \Illuminate\Http\Response |
98
|
|
|
*/ |
99
|
|
|
public function destroy($id) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
// |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|