Forms\Components\Select::make('unit_id') ->label(__('Unit')) ->options(fn() => User::find(Filament::auth()->user()->id)->country->units->pluck('name', 'id')->toArray()) ->searchable() ->afterStateHydrated(function ($record, $component, $state) { $options = $component->getOptions(); if (count($options) === 1) { $component->state(array_key_first($options)); $component->disabled(true); } elseif ($state === null) { $component->state($record?->unit->first()?->id); } }),
$unit = Unit::findOrFail($data['unit_id']);$record->unit()->save($unit);