1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Validator; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use App\EventCategoryTranslation; |
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'); |
|
|
|
|
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
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: