$this->locales->installed(), 'enabled' => $this->locales->enabled(), 'default_locale' => $this->locales->defaultLocale(), ]); } public function update(Request $request): RedirectResponse { $validated = $request->validate([ 'enabled_locales' => ['present', 'array'], 'enabled_locales.*' => ['string', Rule::in($this->locales->installed())], 'default_locale' => ['required', 'string', Rule::in($this->locales->installed())], ]); // English is not optional — it is the translation key rather than a // catalogue, and an install with no language at all is not a state // this screen is allowed to produce. The frontend locks its // checkbox; this is the half that actually enforces it. $enabled = array_values(array_unique([...$validated['enabled_locales'], 'en'])); sort($enabled); // Checked against the list being saved, not the one currently // stored: switching a language off and making it the default in the // same save has to fail rather than half-apply. if (! in_array($validated['default_locale'], $enabled, true)) { throw ValidationException::withMessages([ 'default_locale' => __('The default language has to be one of the languages you are offering.'), ]); } $this->settings->set(Setting::EnabledLocales, $enabled); $this->settings->set(Setting::DefaultLocale, $validated['default_locale']); $this->activity->log(Action::SettingsUpdated, context: ['section' => 'languages']); return back(); } }