currentLocale = App::getLocale(); } public function switchLanguage(string $locale): void { if (!in_array($locale, ['en', 'es'])) { return; } Session::put('locale', $locale); if (Auth::check()) { $user = Auth::user(); $user->locale = $locale; $user->save(); } // Dispatch a browser event — JavaScript reloads the page. // PHP-side redirects break because $this->redirect() runs inside // /livewire/update (the AJAX endpoint), not on the real page URL. $this->dispatch('locale-changed'); } public function render() { return view('livewire.language-switcher'); } }