Passed
Push — dev6 ( 85d655...fe3508 )
by Ron
18:08
created

EquipmentCategoryController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 25
c 1
b 0
f 0
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 8 1
A edit() 0 7 1
A update() 0 9 1
A create() 0 5 1
A destroy() 0 10 1
1
<?php
2
3
namespace App\Http\Controllers\Equipment;
4
5
use App\Events\Equipment\EquipmentCategoryCreatedEvent;
6
use App\Events\Equipment\EquipmentCategoryDeletedEvent;
7
use App\Events\Equipment\EquipmentCategoryUpdatedEvent;
8
use App\Http\Controllers\Controller;
9
use App\Http\Requests\Equipment\EquipmentCategoryRequest;
10
use App\Models\EquipmentCategory;
11
use Inertia\Inertia;
12
13
class EquipmentCategoryController extends Controller
14
{
15
    /**
16
     * Show the form for creating a new Equipment Category
17
     */
18
    public function create()
19
    {
20
        $this->authorize('create', EquipmentCategory::class);
21
22
        return Inertia::render('EquipmentCategory/Create');
23
    }
24
25
    /**
26
     * Store a newly created Equipment Category
27
     */
28
    public function store(EquipmentCategoryRequest $request)
29
    {
30
        $newCat = EquipmentCategory::create($request->only('name'));
31
32
        event(new EquipmentCategoryCreatedEvent($newCat));
33
        return redirect(route('equipment.index'))->with([
34
            'message' => 'New Category Created',
35
            'type'    => 'success',
36
        ]);
37
    }
38
39
    /**
40
     * Show the form for editing the Category Name
41
     */
42
    public function edit($id)
43
    {
44
        $cat = EquipmentCategory::findOrFail($id);
45
        $this->authorize('update', $cat);
46
47
        return Inertia::render('EquipmentCategory/Edit', [
48
            'category' => $cat,
49
        ]);
50
    }
51
52
    /**
53
     * Update the Equipment Category Name
54
     */
55
    public function update(EquipmentCategoryRequest $request, $id)
56
    {
57
        $cat = EquipmentCategory::find($id);
58
        $cat->update($request->only('name'));
59
60
        event(new EquipmentCategoryUpdatedEvent($cat));
1 ignored issue
show
Bug introduced by
It seems like $cat can also be of type null; however, parameter $category of App\Events\Equipment\Equ...tedEvent::__construct() does only seem to accept App\Models\EquipmentCategory, maybe add an additional type check? ( Ignorable by Annotation )

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

60
        event(new EquipmentCategoryUpdatedEvent(/** @scrutinizer ignore-type */ $cat));
Loading history...
61
        return redirect(route('equipment.index'))->with([
62
            'message' => 'Category Updated',
63
            'type'    => 'success',
64
        ]);
65
    }
66
67
    /**
68
     * Remove the Equipment Category
69
     */
70
    public function destroy($id)
71
    {
72
        $cat = EquipmentCategory::find($id);
73
        $this->authorize('delete', $cat);
74
        $cat->delete();
75
76
        event(new EquipmentCategoryDeletedEvent($cat));
1 ignored issue
show
Bug introduced by
It seems like $cat can also be of type null; however, parameter $category of App\Events\Equipment\Equ...tedEvent::__construct() does only seem to accept App\Models\EquipmentCategory, maybe add an additional type check? ( Ignorable by Annotation )

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

76
        event(new EquipmentCategoryDeletedEvent(/** @scrutinizer ignore-type */ $cat));
Loading history...
77
        return back()->with([
78
            'message' => 'Equipment Category Deleted',
79
            'type'    => 'danger',
80
        ]);
81
    }
82
}
83