schema([ Forms\Components\Select::make('currency_code') ->options(function () { $existing_currencies = $this->getOwnerRecord()->credits->pluck('currency_code'); return Currency::whereNotIn('code', $existing_currencies)->pluck('code', 'code'); }) ->live() ->required(), Forms\Components\TextInput::make('amount') ->required() ->label('Amount') // Suffix based on chosen currency ->prefix(fn (Get $get) => Currency::where('code', $get('currency_code'))->first()?->prefix) ->suffix(fn (Get $get) => Currency::where('code', $get('currency_code'))->first()?->suffix) ->live(onBlur: true) ->mask(RawJs::make( <<<'JS' $money($input, '.', '', 2) JS )) ->numeric() ->minValue(0), ]); } public function table(Table $table): Table { return $table ->recordTitleAttribute('currency.code') ->columns([ Tables\Columns\TextColumn::make('currency.code'), Tables\Columns\TextColumn::make('formattedAmount')->label('Formatted Amount'), Tables\Columns\TextInputColumn::make('amount')->label('Amount'), ]) ->filters([]) ->headerActions([ Tables\Actions\CreateAction::make()->disabled(function () { $existing_currencies = $this->getOwnerRecord()->credits->pluck('currency_code'); return count(Currency::whereNotIn('code', $existing_currencies)->pluck('code', 'code')) <= 0; }), ]) ->actions([ Tables\Actions\DeleteAction::make(), ]); } }