foreach (Locales::where('origin_country', session()->get('origin_country'))->get() ->sortBy(function ($locale) { // Custom logic to sort "English" first, then alphabetically by title return $locale->title === 'English' ? -1 : $locale->title; }) as $locale) { $tabs[] = Tabs\Tab::make($locale->title) ->schema([ Grid::make()->schema([ Forms\Components\TextInput::make('title') ->label("Title ($locale->locale)") ->required() ->maxLength(100) ->afterStateHydrated(function (Forms\Components\TextInput $component, string $state, $record) use ($locale) { $component->state($record->locales() ->where('locales_offer.locale', $locale->locale) ->first() ->pivot->title ?? $record->title); }) ->live() ->key('title'), // Needed for getComponent call Forms\Components\TextInput::make('readmore') ->prefix(self::$prefix) ->required() ->maxLength(255), Forms\Components\Textarea::make('description') ->label("Description ($locale->locale)") ->maxLength(2000) ->required() ->columnSpanFull() ->afterStateHydrated(function (Forms\Components\Textarea $component, string $state, $record) use ($locale) { $component->state($record->locales() ->where('locales_offer.locale', $locale->locale) ->first() ->pivot->description ?? $record->description); }) ->key('description'), // Needed for getComponent call ])->key('dynamicFields'), Fieldset::make('Offer Image') ->schema([ Forms\Components\FileUpload::make('avatar') ->image() ->disk('public') ->directory('offers') ->imageEditor() ->imageEditorMode(2), ]), Fieldset::make('Location & Category') ->schema([ Forms\Components\Select::make('location_id') ->relationship( 'location', fn (Builder $query) => $query->orderBy('state'), fn (Builder $query) => $query->where('origin_country', \session()->get('origin_country')) ) ->getOptionLabelFromRecordUsing( fn (Model $record) => "{$record->city}, {$record->state}, {$record->zip}" ) ->searchable() ->preload() ->required(), Forms\Components\Select::make('category') ->options([ 'housing' => 'Housing', 'employment' => 'Employment', 'benefits' => 'Benefits', 'disabilities' => 'Disability', 'income' => 'Income', 'utilities' => 'Utilities', 'dependents' => 'Dependents' ]) ->required(), ]) ]); }