https://www.nike.com/th/t/รองเท้าผู้-air-force-1-07-WrLlWX/CW2288-111?cp=11357671355_search_%7Cth%7CPMax:+TH+-+Smart+Shopping+-+Brand%7C%7CGOOGLE&gad_source=1&gbraid=0AAAAADLM_Zk46u-Ws6BnF93pFK2j4QcT2&gclid=CjwKCAjwvKi4BhABEiwAH2gcw_7jvIHZETI4DRxbYgnEU-OJKRqKfsLhXmYoGHsVNDw_tqUd6_Q5PhoCenEQAvD_BwE&gclsrc=aw.ds
Forms\Components\Select::make('product_id') ->label('Product') ->options(Product::query()->pluck('name', 'id')) ->required() ->live(onBlur: true) ->afterStateUpdated( fn( $state, Forms\Set $set ) => $set( 'unit_price', Number::format( Product::find($state)?->price * Product::find($state)?->currency->rate * (1 + Product::find($state)?->margin / 100) ?? 0 ), ) )
Forms\Components\TextInput::make('unit_price') ->label('Unit Price') ->disabled() ->formatStateUsing(fn (?int $state): ?int => $state) ->mask(RawJs::make(<<<'JS' $money($input, ',', '.') JS)) ->required()//
Forms\Components\Select::make('product_id') ->label('Product') ->options(Product::query()->pluck('name', 'id')) ->required() ->reactive() ->afterStateUpdated( fn( $state, Forms\Set $set ) => $set( 'unit_price', Product::find($state)?->price * Product::find($state)?->currency->rate * (1 + Product::find($state)?->margin / 100) ?? 0, )