1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PWWEB\Localisation\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Flash; |
|
|
|
|
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use PWWEB\Localisation\Middleware\Locale; |
9
|
|
|
use PWWEB\Localisation\Repositories\LanguageRepository; |
10
|
|
|
use PWWEB\Localisation\Requests\CreateLanguageRequest; |
11
|
|
|
use PWWEB\Localisation\Requests\UpdateLanguageRequest; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* PWWEB\Localisation\Controllers\LanguageController LanguageController. |
15
|
|
|
* |
16
|
|
|
* The CRUD controller for Language |
17
|
|
|
* Class LanguageController |
18
|
|
|
* |
19
|
|
|
* @author Frank Pillukeit <[email protected]> |
20
|
|
|
* @author Richard Browne <[email protected] |
21
|
|
|
* @copyright 2020 pw-websolutions.com |
22
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
23
|
|
|
*/ |
24
|
|
|
class LanguageController extends Controller |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Repository of Languages to be used throughout the controller. |
28
|
|
|
* |
29
|
|
|
* @var \PWWEB\Localisation\Repositories\LanguageRepository |
30
|
|
|
*/ |
31
|
|
|
private $languageRepository; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor for the Language controller. |
35
|
|
|
* |
36
|
|
|
* @param \PWWEB\Localisation\Repositories\LanguageRepository $languageRepo Repository of Languages |
37
|
|
|
*/ |
38
|
|
|
public function __construct(LanguageRepository $languageRepo) |
39
|
|
|
{ |
40
|
|
|
$this->languageRepository = $languageRepo; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Display a listing of the Language. |
45
|
|
|
* |
46
|
|
|
* @param Request $request Request containing the information for filtering. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\View\View |
49
|
|
|
*/ |
50
|
|
|
public function index(Request $request) |
51
|
|
|
{ |
52
|
|
|
$languages = $this->languageRepository->all(); |
53
|
|
|
|
54
|
|
|
return view('localisation::languages.index') |
55
|
|
|
->with('languages', $languages); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Show the form for creating a new Language. |
60
|
|
|
* |
61
|
|
|
* @return \Illuminate\View\View |
62
|
|
|
*/ |
63
|
|
|
public function create() |
64
|
|
|
{ |
65
|
|
|
return view('localisation::languages.create'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Store a newly created Language in storage. |
70
|
|
|
* |
71
|
|
|
* @param CreateLanguageRequest $request Request containing the information to be stored. |
72
|
|
|
* |
73
|
|
|
* @return \Illuminate\Http\RedirectResponse |
74
|
|
|
*/ |
75
|
|
|
public function store(CreateLanguageRequest $request) |
76
|
|
|
{ |
77
|
|
|
$input = $request->all(); |
78
|
|
|
|
79
|
|
|
$language = $this->languageRepository->create($input); |
|
|
|
|
80
|
|
|
|
81
|
|
|
Flash::success('Language saved successfully.'); |
82
|
|
|
|
83
|
|
|
return redirect(route('localisation.languages.index')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Display the specified Language. |
88
|
|
|
* |
89
|
|
|
* @param int $id ID of the Language to be displayed. Used for retrieving currently held data. |
90
|
|
|
* |
91
|
|
|
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse |
92
|
|
|
*/ |
93
|
|
|
public function show($id) |
94
|
|
|
{ |
95
|
|
|
$language = $this->languageRepository->find($id); |
96
|
|
|
|
97
|
|
|
if (true === empty($language)) { |
98
|
|
|
Flash::error('Language not found'); |
99
|
|
|
|
100
|
|
|
return redirect(route('localisation.languages.index')); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return view('localisation::languages.show') |
104
|
|
|
->with('language', $language); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Show the form for editing the specified Language. |
109
|
|
|
* |
110
|
|
|
* @param int $id ID of the Language to be edited. Used for retrieving currently held data. |
111
|
|
|
* |
112
|
|
|
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse |
113
|
|
|
*/ |
114
|
|
|
public function edit($id) |
115
|
|
|
{ |
116
|
|
|
$language = $this->languageRepository->find($id); |
117
|
|
|
|
118
|
|
|
if (true === empty($language)) { |
119
|
|
|
Flash::error('Language not found'); |
120
|
|
|
|
121
|
|
|
return redirect(route('localisation.languages.index')); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return view('localisation::languages.edit')->with('language', $language); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Update the specified Language in storage. |
129
|
|
|
* |
130
|
|
|
* @param int $id ID of the Language to be updated. |
131
|
|
|
* @param UpdateLanguageRequest $request Request containing the information to be updated. |
132
|
|
|
* |
133
|
|
|
* @return \Illuminate\Http\RedirectResponse |
134
|
|
|
*/ |
135
|
|
|
public function update($id, UpdateLanguageRequest $request) |
136
|
|
|
{ |
137
|
|
|
$language = $this->languageRepository->find($id); |
138
|
|
|
|
139
|
|
|
if (true === empty($language)) { |
140
|
|
|
Flash::error('Language not found'); |
141
|
|
|
|
142
|
|
|
return redirect(route('localisation.languages.index')); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$language = $this->languageRepository->update($request->all(), $id); |
|
|
|
|
146
|
|
|
|
147
|
|
|
Flash::success('Language updated successfully.'); |
148
|
|
|
|
149
|
|
|
return redirect(route('localisation.languages.index')); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Remove the specified Language from storage. |
154
|
|
|
* |
155
|
|
|
* @param int $id ID of the Language to be destroyed. |
156
|
|
|
* |
157
|
|
|
* @throws \Exception |
158
|
|
|
* |
159
|
|
|
* @return \Illuminate\Http\RedirectResponse |
160
|
|
|
*/ |
161
|
|
|
public function destroy($id) |
162
|
|
|
{ |
163
|
|
|
$language = $this->languageRepository->find($id); |
164
|
|
|
|
165
|
|
|
if (true === empty($language)) { |
166
|
|
|
Flash::error('Language not found'); |
167
|
|
|
|
168
|
|
|
return redirect(route('localisation.languages.index')); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$this->languageRepository->delete($id); |
172
|
|
|
|
173
|
|
|
Flash::success('Language deleted successfully.'); |
174
|
|
|
|
175
|
|
|
return redirect(route('localisation.languages.index')); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Switch the locale. |
180
|
|
|
* |
181
|
|
|
* @param Request $request Laravel request instance. |
182
|
|
|
* @param string $locale Locale to change to. |
183
|
|
|
* |
184
|
|
|
* @return \Illuminate\Http\RedirectResponse |
185
|
|
|
*/ |
186
|
|
|
public function changeLocale(Request $request, $locale) |
187
|
|
|
{ |
188
|
|
|
$check = $this->languageRepository->isLocaleActive($locale); |
189
|
|
|
// If a locale does not match any of the ones allowed, go back without doing anything. |
190
|
|
|
if (true === is_null($check)) { |
191
|
|
|
return redirect()->back(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
// Set the right sessions. |
195
|
|
|
$request->session()->put(Locale::SESSION_KEY, $locale); |
196
|
|
|
// app()->setLocale($locale); |
197
|
|
|
// \LangCountry::setAllSessions($lang_country); |
198
|
|
|
|
199
|
|
|
// If a user is logged in and it has a lang_country property, set the new lang_country. |
200
|
|
|
/* |
201
|
|
|
* Todo Set language to user options |
202
|
|
|
* if (Auth::user() && array_key_exists('lang_country', Auth::user()->getAttributes())) { |
203
|
|
|
* |
204
|
|
|
try { |
205
|
|
|
\Auth::user()->lang_country = $lang_country; |
206
|
|
|
\Auth::user()->save(); |
207
|
|
|
} catch (\Exception $e) { |
208
|
|
|
\Log::error(get_class($this).' at '.__LINE__.': '.$e->getMessage()); |
209
|
|
|
} |
210
|
|
|
}*/ |
211
|
|
|
|
212
|
|
|
return redirect()->back(); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths