Completed
Branch dev4 (2f299a)
by Ron
08:25
created

SystemCategoriesController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
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)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

78
    public function destroy(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
        //
81
    }
82
}
83