/** * Sets and stores the locale in the session. * * @param SetLocaleRequest $request * @return mixed */ public function setLocale(SetLocaleRequest $request) { $locale = $request->input('locale'); if (!$this->repository->isAvailable($locale)) { return redirect()->back()->withErrors("Locale {$locale} is not available"); } session()->set($this->getSessionKey(), $locale); return redirect()->back(); }
/** * Returns the session locale, replacing unavailable with default. * * @return bool|string */ protected function getValidSessionLocale() { $locale = $this->getSessionLocale(); if (!$locale) { return false; } if (!$this->repository->isAvailable($locale)) { $locale = $this->repository->getDefault(); } return $locale; }