1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Carbon\Carbon; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Support\Facades\Auth; |
9
|
|
|
use Illuminate\Support\Facades\Log; |
10
|
|
|
use App\SystemCategories; |
11
|
|
|
|
12
|
|
|
class SystemCategoriesController extends Controller |
13
|
|
|
{ |
14
|
|
|
// Bring up the system categories to possibly Edit |
15
|
|
|
public function index() |
16
|
|
|
{ |
17
|
|
|
$categories = SystemCategories::all(); |
18
|
|
|
|
19
|
|
|
return view('installer.selectCategory', [ |
20
|
|
|
'cats' => $categories |
21
|
|
|
]); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// Show the new Category form |
25
|
|
|
public function create() |
26
|
|
|
{ |
27
|
|
|
return view('installer.form.newCat'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// Submit the new category form |
31
|
|
|
public function store(Request $request) |
32
|
|
|
{ |
33
|
|
|
$request->validate([ |
34
|
|
|
'name' => 'required|string|unique:system_categories|regex:/^[a-zA-Z0-9_ ]*$/' |
35
|
|
|
]); |
36
|
|
|
|
37
|
|
|
$cat = SystemCategories::create([ |
38
|
|
|
'name' => $request->name |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
Log::info('New System Category Created', ['cat_name' => $request->name, 'user_id' => Auth::user()->user_id]); |
42
|
|
|
|
43
|
|
|
Log::info('New System Category - '.$request->name.' created by User ID-'.Auth::user()->user_id); |
44
|
|
|
|
45
|
|
|
return redirect()->back()->with('success', 'Category Successfully Added. <a href="'.route('installer.newSys', urlencode($cat->name)).'">Add System</a>'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Bring up the Edit Category form |
49
|
|
|
public function edit($id) |
50
|
|
|
{ |
51
|
|
|
$cat = SystemCategories::find($id); |
52
|
|
|
|
53
|
|
|
return view('installer.form.editCategory', [ |
54
|
|
|
'details' => $cat |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Submit the modified category name |
59
|
|
|
public function update(Request $request, $id) |
60
|
|
|
{ |
61
|
|
|
$request->validate([ |
62
|
|
|
'name' => 'required|string|unique:system_categories|regex:/^[a-zA-Z0-9_ ]*$/' |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
SystemCategories::find($id)->update([ |
66
|
|
|
'name' => $request->name |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
return redirect()->back()->with('success', 'Category Successfully Modified. <a href="'.route('installer.newSys', urlencode($request->name)).'">Add System</a>'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Remove the specified resource from storage. |
74
|
|
|
* |
75
|
|
|
* @param int $id |
76
|
|
|
* @return \Illuminate\Http\Response |
77
|
|
|
*/ |
78
|
|
|
public function destroy($id) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
// |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.