Passed
Push — master ( c430e0...09e8fc )
by Davide
02:42 queued 11s
created

EventCategoryTranslationController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 130
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A edit() 0 12 1
A update() 0 15 1
A store() 0 21 2
A destroy() 0 7 1
A __construct() 0 3 1
A create() 0 8 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Http\Controllers;
4
5
use Validator;
6
use Illuminate\Support\Str;
7
use Illuminate\Http\Request;
8
use App\EventCategoryTranslation;
0 ignored issues
show
Bug introduced by
The type App\EventCategoryTranslation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class EventCategoryTranslationController extends Controller
11
{
12
    /* Restrict the access to this resource just to logged in users */
13
    public function __construct()
14
    {
15
        $this->middleware('admin');
16
    }
17
18
    /**
19
     * Display a listing of the resource.
20
     *
21
     * @return \Illuminate\Http\Response
22
     */
23
    /*public function index()
24
    {
25
        //
26
    }*/
27
28
    /**
29
     * Show the form for creating a new resource.
30
     * @param int $eventCategoryId
31
     * @param int $languageCode
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function create($eventCategoryId, $languageCode)
35
    {
36
        $selectedLocaleName = $this->getSelectedLocaleName($languageCode);
37
38
        return view('eventCategoryTranslations.create')
39
                ->with('eventCategoryId', $eventCategoryId)
40
                ->with('languageCode', $languageCode)
41
                ->with('selectedLocaleName', $selectedLocaleName);
42
    }
43
44
    /**
45
     * Store a newly created resource in storage.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function store(Request $request)
51
    {
52
        // Validate form datas
53
        $validator = Validator::make($request->all(), [
54
                'name' => 'required',
55
            ]);
56
        if ($validator->fails()) {
57
            return back()->withErrors($validator)->withInput();
58
        }
59
60
        $eventCategoryTranslation = new EventCategoryTranslation();
61
        $eventCategoryTranslation->event_category_id = $request->get('event_category_id');
62
        $eventCategoryTranslation->locale = $request->get('language_code');
63
64
        $eventCategoryTranslation->name = $request->get('name');
65
        $eventCategoryTranslation->slug = Str::slug($eventCategoryTranslation->name, '-');
66
67
        $eventCategoryTranslation->save();
68
69
        return redirect()->route('eventCategories.index')
70
                        ->with('success', 'Translation created successfully.');
71
    }
72
73
    /**
74
     * Display the specified resource.
75
     *
76
     * @param  \App\EventCategoryTranslation  $eventCategoryTranslation
77
     * @return \Illuminate\Http\Response
78
     */
79
    /*public function show(EventCategoryTranslation $eventCategoryTranslation)
80
    {
81
        //
82
    }*/
83
84
    /**
85
     * Show the form for editing the specified resource.
86
     * @param int $eventCategoryId
87
     * @param int $languageCode
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function edit($eventCategoryId, $languageCode)
91
    {
92
        $eventCategoryTranslation = EventCategoryTranslation::where('event_category_id', $eventCategoryId)
93
                        ->where('locale', $languageCode)
94
                        ->first();
95
96
        $selectedLocaleName = $this->getSelectedLocaleName($languageCode);
97
98
        return view('eventCategoryTranslations.edit', compact('eventCategoryTranslation'))
99
                    ->with('eventCategoryId', $eventCategoryId)
100
                    ->with('languageCode', $languageCode)
101
                    ->with('selectedLocaleName', $selectedLocaleName);
102
    }
103
104
    /**
105
     * Update the specified resource in storage.
106
     *
107
     * @param  \Illuminate\Http\Request  $request
108
     * @return \Illuminate\Http\Response
109
     */
110
    public function update(Request $request)
111
    {
112
        request()->validate([
113
            'name' => 'required',
114
        ]);
115
116
        $eventCategoryTranslation = EventCategoryTranslation::where('id', $request->get('event_category_translation_id'));
117
118
        $event_category_t['name'] = $request->get('name');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$event_category_t was never initialized. Although not strictly required by PHP, it is generally a good practice to add $event_category_t = array(); before regardless.
Loading history...
119
        $event_category_t['slug'] = Str::slug($request->get('name'), '-');
120
121
        $eventCategoryTranslation->update($event_category_t);
122
123
        return redirect()->route('eventCategories.index')
124
                        ->with('success', 'Translation updated successfully');
125
    }
126
127
    /**
128
     * Remove the specified resource from storage.
129
     *
130
     * @param  \App\EventCategoryTranslation  $eventCategoryTranslation
131
     * @return \Illuminate\Http\Response
132
     */
133
    public function destroy($eventCategoryTranslationId)
134
    {
135
        $eventCategoryTranslation = EventCategoryTranslation::find($eventCategoryTranslationId);
136
        $eventCategoryTranslation->delete();
137
138
        return redirect()->route('eventCategories.index')
139
                        ->with('success', __('messages.event_category_translation_deleted_successfully'));
140
    }
141
}
142