Move array of available locales to config/app.php, making it easier to access
MODIFY
app/Http/Controllers/SettingsController.php
app/Http/Controllers/SettingsController.php
@@ -12,12 +12,10 @@ class SettingsController extends Controller {
public function index() {
$user = Auth::user();
- //
- $languages = ['en', 'nl', 'dk'];
-
- $tags = $user->tags;
-
- return view('settings', compact('languages', 'tags'));
+ return view('settings', [
+ 'languages' => config('app.locales'),
+ 'tags' => $user->tags
+ ]);
}
public function store(Request $request) {

MODIFY
config/app.php
config/app.php
@@ -79,6 +79,12 @@ return [
'locale' => 'en',
+ 'locales' => [
+ 'en' => 'English',
+ 'nl' => 'Dutch',
+ 'dk' => 'Danish'
+ ],
+
/*
|--------------------------------------------------------------------------
| Application Fallback Locale

MODIFY
resources/views/settings.blade.php
resources/views/settings.blade.php
<div class="input input--small">
<label>Language</label>
<select name="language">
- @foreach ($languages as $language)
- <option value="{{ $language }}" @if (Auth::user()->language === $language) selected @endif>{{ $language }}</option>
+ @foreach ($languages as $key => $value)
+ <option value="{{ $key }}" @if (Auth::user()->language === $key) selected @endif>{{ $value }}</option>
@endforeach
</select>
+ @include('partials.validation_error', ['payload' => 'language'])
</div>
<button>Update</button>
</form>

Move array of available locales to config/app.php, making it easier to access