Completed
Push — dev5 ( 92471b...222021 )
by Ron
08:43
created

CategoriesController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
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([
0 ignored issues
show
Unused Code introduced by
The assignment to $cat is dead and can be removed.
Loading history...
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)
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

53
    public function show(/** @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...
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)
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

99
    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...
100
    {
101
        //
102
    }
103
}
104