EventCategoryController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\EventCategoryStoreRequest;
6
use App\Services\EventCategoryService;
7
8
class EventCategoryController extends Controller
9
{
10
    private $eventCategoryService;
11
12
    public function __construct(
13
        EventCategoryService $eventCategoryService
14
    )
15
    {
16
        $this->eventCategoryService = $eventCategoryService;
17
    }
18
    /**
19
     * Display a listing of the resource.
20
     *
21
     * @return \Illuminate\Contracts\View\View
22
     */
23
    public function index()
24
    {
25
        $eventCategories = $this->eventCategoryService->getEventCategories();
26
27
        return view('eventCategories.index', [
28
            'eventCategories' => $eventCategories,
29
        ]);
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Contracts\View\View
36
     */
37
    public function create()
38
    {
39
        return view('eventCategories.create');
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param \App\Http\Requests\EventCategoryStoreRequest $request
46
     *
47
     * @return \Illuminate\Http\RedirectResponse
48
     */
49
    public function store(EventCategoryStoreRequest $request)
50
    {
51
        $this->eventCategoryService->createEventCategory($request);
52
53
        return redirect()->route('eventCategories.index')
54
            ->with('success','Event category created successfully');
55
    }
56
57
    /**
58
     * Show the form for editing the specified resource.
59
     *
60
     * @param int $eventCategoryId
61
     *
62
     * @return \Illuminate\Contracts\View\View
63
     */
64
    public function edit(int $eventCategoryId)
65
    {
66
        $eventCategory = $this->eventCategoryService->getById($eventCategoryId);
67
68
        return view('eventCategories.edit', [
69
            'eventCategory' => $eventCategory,
70
        ]);
71
    }
72
73
    /**
74
     * Update the specified resource in storage.
75
     *
76
     * @param \App\Http\Requests\EventCategoryStoreRequest $request
77
     * @param int $eventCategoryId
78
     *
79
     * @return \Illuminate\Http\RedirectResponse
80
     */
81
    public function update(EventCategoryStoreRequest $request, int $eventCategoryId)
82
    {
83
        $this->eventCategoryService->updateEventCategory($request, $eventCategoryId);
84
85
        return redirect()->route('eventCategories.index')
86
            ->with('success','Event category updated successfully');
87
    }
88
89
    /**
90
     * Remove the specified resource from storage.
91
     *
92
     * @param int $eventCategoryId
93
     *
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96
    public function destroy(int $eventCategoryId)
97
    {
98
        $this->eventCategoryService->deleteEventCategory($eventCategoryId);
99
100
        return redirect()->route('eventCategories.index')
101
            ->with('success','Event category deleted successfully');
102
    }
103
}
104