Passed
Push — dev5a ( f24c41...668142 )
by Ron
10:56
created

EquipmentCategoriesController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 45
ccs 19
cts 19
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 4 1
A store() 0 5 1
A update() 0 6 1
A create() 0 4 1
A destroy() 0 9 2
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Domains\Equipment\GetCategory;
6
use App\Domains\Equipment\SetCategory;
7
use App\Http\Controllers\Controller;
8
use App\Http\Requests\Equipment\CategoryRequest;
9
use Illuminate\Http\Request;
10
11
use Illuminate\Support\Facades\Auth;
12
use Illuminate\Support\Facades\Log;
13
14
class EquipmentCategoriesController extends Controller
15
{
16
    //  Show for to creat a new equipment category
17 2
    public function create()
18
    {
19 2
        return view('admin.equipment.editCategory', [
20 2
            'data' => null,
21
        ]);
22
    }
23
24
    //  Store the new equipment category
25 2
    public function store(CategoryRequest $request)
26
    {
27 2
        (new SetCategory)->createCategory($request);
28 2
        Log::notice('New Equipment Category created by '.Auth::user()->full_name.'.  Data - ', $request->toArray());
29 2
        return response()->json(['success' => true]);
30
    }
31
32
    //  Edit an existing category
33 2
    public function edit($id)
34
    {
35 2
        return view('admin.equipment.editCategory', [
36 2
            'data' => (new GetCategory)->getCategoryData($id),
37
        ]);
38
    }
39
40
    //  Update an existing category
41 2
    public function update(CategoryRequest $request, $id)
42
    {
43 2
        (new SetCategory)->updateCategory($request, $id);
44 2
        Log::notice('Category ID '.$id.' - '.$request->name.' has been updated by '.Auth::user()->full_name);
45
46 2
        return response()->json(['success' => true]);
47
    }
48
49
    //  Delete an equipment category - note:  this will fail if equipment is assigned to the category
50 4
    public function destroy($id)
51
    {
52 4
        $res = (new SetCategory)->deleteCategory($id);
53 4
        if($res)
54
        {
55 2
            Log::notice('Equipment Category ID '.$id.' has been deleted by '.Auth::user()->full_name);
56
        }
57
58 4
        return response()->json(['success' => $res]);
59
    }
60
}
61