OrganizerController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
dl 0
loc 126
ccs 0
cts 35
cp 0
rs 10
c 1
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
A __construct() 0 4 1
A store() 0 8 1
A index() 0 10 1
A destroy() 0 8 1
A update() 0 8 1
A show() 0 5 1
A edit() 0 8 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Helpers\Helper;
6
use App\Http\Requests\OrganizerSearchRequest;
7
use App\Http\Requests\OrganizerStoreRequest;
8
use App\Models\Organizer;
9
use App\Services\OrganizerService;
10
use App\Traits\CheckPermission;
11
use Illuminate\Http\RedirectResponse;
12
13
class OrganizerController extends Controller
14
{
15
    use CheckPermission;
0 ignored issues
show
Bug introduced by
The trait App\Traits\CheckPermission requires the property $user_id which is not provided by App\Http\Controllers\OrganizerController.
Loading history...
16
17
    private OrganizerService $organizerService;
18
19
    public function __construct(
20
        OrganizerService $organizerService
21
    ) {
22
        $this->organizerService = $organizerService;
23
    }
24
25
    /**
26
     * Display a listing of the resource.
27
     *
28
     * @param \App\Http\Requests\OrganizerSearchRequest $request
29
     *
30
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
31
     */
32
    public function index(OrganizerSearchRequest $request)
33
    {
34
        $this->checkPermission('organizers.view');
35
36
        $searchParameters = Helper::getSearchParameters($request, Organizer::SEARCH_PARAMETERS);
37
        $organizers = $this->organizerService->getOrganizers(20, $searchParameters);
38
39
        return view('organizers.index', [
40
            'organizers' => $organizers,
41
            'searchParameters' => $searchParameters,
42
        ]);
43
    }
44
45
    /**
46
     * Show the form for creating a new resource.
47
     *
48
     * @return \Illuminate\Contracts\View\View
49
     */
50
    public function create()
51
    {
52
        $this->checkPermission('organizers.create');
53
54
        return view('organizers.create');
55
    }
56
57
    /**
58
     * Store a newly created resource in storage.
59
     *
60
     * @param \App\Http\Requests\OrganizerStoreRequest $request
61
     *
62
     * @return \Illuminate\Http\RedirectResponse
63
     */
64
    public function store(OrganizerStoreRequest $request): RedirectResponse
65
    {
66
        $this->checkPermission('organizers.create');
67
68
        $this->organizerService->createOrganizer($request);
69
70
        return redirect()->route('organizers.index')
71
            ->with('success', 'Organizer updated successfully');
72
    }
73
74
    /**
75
     * Display the specified resource.
76
     *
77
     * @param int $organizerId
78
     *
79
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
80
     */
81
    public function show(string $organizerSlug)
82
    {
83
        $organizer = $this->organizerService->getBySlug($organizerSlug);
84
85
        return view('organizers.show', compact('organizer'));
86
    }
87
88
    /**
89
     * Show the form for editing the specified resource.
90
     *
91
     * @param int $organizerId
92
     *
93
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
94
     */
95
    public function edit(int $organizerId)
96
    {
97
        $this->checkPermission('organizers.edit');
98
99
        $organizer = $this->organizerService->getById($organizerId);
100
101
        return view('organizers.edit', [
102
            'organizer' => $organizer
103
        ]);
104
    }
105
106
    /**
107
     * Update the specified resource in storage.
108
     *
109
     * @param \App\Http\Requests\OrganizerStoreRequest $request
110
     * @param int $organizerId
111
     *
112
     * @return \Illuminate\Http\RedirectResponse
113
     */
114
    public function update(OrganizerStoreRequest $request, int $organizerId): RedirectResponse
115
    {
116
        $this->checkPermission('organizers.edit');
117
118
        $this->organizerService->updateOrganizer($request, $organizerId);
119
120
        return redirect()->route('organizers.index')
121
            ->with('success', 'Organizer updated successfully');
122
    }
123
124
    /**
125
     * Remove the specified resource from storage.
126
     *
127
     * @param int $organizerId
128
     *
129
     * @return \Illuminate\Http\RedirectResponse
130
     */
131
    public function destroy(int $organizerId): RedirectResponse
132
    {
133
        $this->checkPermission('organizers.delete');
134
135
        $this->organizerService->deleteOrganizer($organizerId);
136
137
        return redirect()->route('organizers.index')
138
            ->with('success', 'Organizer deleted successfully');
139
    }
140
}
141