emptyMessage = __('Loading...'); $this->updateLocalesOptions($options); $locale = $locale ?? session('locale'); // Extract lang_code values from the options collection $availableLocales = $this->options ? $this->options->pluck('lang_code')->all() : []; if (!in_array($locale, $availableLocales)) { $locale = null; } $this->localeSelected = $locale; } public function updateLocalesOptions($options) { // Set loading message while fetching options $this->emptyMessage = __('Loading...'); if ($options) { $options = DB::table('languages') ->whereIn('lang_code', $options) ->orderBy('name') ->get(['id','lang_code','name']); $this->options = $options->map(function ($item, $key) { return [ 'id' => $item->id, 'lang_code' => $item->lang_code, 'name' => __('messages.' . $item->name)]; }); } } /** * When component is updated * * @return void */ public function updated() { if ($this->localeSelected) { $this->dispatch('localeSelected', $this->localeSelected); } } public function render() { return view('livewire.add-translation-selectbox'); } }