FilamentF
Filament3y ago
Mdk

Custom Action that calls "save" doesn't actually save the model

So I'm trying to put a save button elsewhere in an Edit page
Grid::make('card_payment')
    ->visible(fn($get) => $get('payment_method') === 'card')
    ->schema([
        TextInput::make('balance_used')
            ->label(__uf('use balance'))
            ->hint(__uf('balance available').': '.money(auth()->user()->balance, env('CASHIER_CURRENCY')))
            ->numeric()
            ->minValue(0)
            ->maxValue(auth()->user()->balance)
            ->live(debounce:500)
            //->afterStateUpdated(fn($state) => dump($state))
            ->prefix('€'),
        Actions::make([
            Actions\Action::make('paybycard')
                ->label(fn($record, $get) =>
                    __uf('proceed to payment').' - '.money($record->order_total + $record->shipping_cost - ($get('balance_to_use')?:0), env('CASHIER_CURRENCY')))
                ->submit('save')
        ])->fullWidth()
    ])


Both payment_method and balance_used are properties of the model that is being edited
I tried with both submit('save') as well as action('save'), they both trigger the validation and display the success notification, but the model is not updated and neither protected function beforeSave() or protected function afterSave() are called.. what am I doing wrong?
My plan was to save the order and then redirect to the payment page in the afterSave method, I would've used a custom action but I couldn't manage to trigger the validation with that
Was this page helpful?