Is there any other way to write this?

Forms\Components\Select::make('year_id')
                ->options(Year::all()->pluck('year', 'id')->toArray())
                ->afterStateHydrated(function ($set, $state, $record) {
                    if (isset($record->product_id)) {
                            $set('year_id', Product::with('year')->where('id',  $record->product_id)->value('year_id'));
                        }
                 })
                ->label('Year')
                ->reactive()
                ->required(),
`
Was this page helpful?