Completed
Branch master (2f299a)
by Ron
11:00
created

SystemCategoriesController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A edit() 0 6 1
A destroy() 0 2 1
A store() 0 15 1
A create() 0 3 1
A update() 0 11 1
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>');
1 ignored issue
show
Bug introduced by
The property name does not seem to exist on App\SystemCategories. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
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