/** * 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(); }
/** * Bind data to the view. * * @param View $view */ public function compose(View $view) { $view->with(['localized' => $this->repository->isLocalized(), 'currentLocale' => app()->getLocale(), 'availableLocales' => $this->repository->getAvailable()]); }
/** * @param \Illuminate\Http\Request $request * @return string */ protected function getRequestLocale($request) { $locales = array_unique(array_merge([$this->repository->getDefault()], $this->repository->getAvailable())); return $request->getPreferredLanguage($locales); }