How to refresh relation manager on action?

Hi guys, I am trying to figure out how to refresh relation manager after header action from infolist?
1 Reply
Trauma Zombie
Trauma ZombieOP6mo ago
This is my action:
Action::make('recalculateCommissions')
->label('Recalculate commissions')
->icon('heroicon-o-calculator')
->beforeFormFilled(function (Contract $record, Action $action): void {
$canDelete = $record->commissions->every(function (Commission $commission): bool {
return is_null($commission->invoice_id) && is_null($commission->paid_at);
});

if (! $canDelete) {
Notification::make()
->title('It is not possible to recalculate commissions')
->body('There are already invoices or payments for some commissions. It is not possible to recalculate commissions.')
->warning()
->persistent()
->send();

$action->halt();
}
})
->form([
MoneyInput::make('total_commission')
->label('Total commission')
->default(fn (Contract $record): ?float => $record->total_commission)
->required()
->minValue(0),
])
->modalWidth(MaxWidth::Medium)
->modalSubmitActionLabel('Recalculate')
->modalDescription('All commissions of this contract will be deleted and recalculated.')
->action(function (Contract $record, array $data): void {
$record->update([
'total_commission' => $data['total_commission'],
]);

(new RecalculateCommissions())->execute($record);

Notification::make()
->title('Commissions recalculated')
->body('Commissions have been recalculated successfully.')
->success()
->send();
})
->visible(auth()->user()->hasRole(UserRole::Administrator));
Action::make('recalculateCommissions')
->label('Recalculate commissions')
->icon('heroicon-o-calculator')
->beforeFormFilled(function (Contract $record, Action $action): void {
$canDelete = $record->commissions->every(function (Commission $commission): bool {
return is_null($commission->invoice_id) && is_null($commission->paid_at);
});

if (! $canDelete) {
Notification::make()
->title('It is not possible to recalculate commissions')
->body('There are already invoices or payments for some commissions. It is not possible to recalculate commissions.')
->warning()
->persistent()
->send();

$action->halt();
}
})
->form([
MoneyInput::make('total_commission')
->label('Total commission')
->default(fn (Contract $record): ?float => $record->total_commission)
->required()
->minValue(0),
])
->modalWidth(MaxWidth::Medium)
->modalSubmitActionLabel('Recalculate')
->modalDescription('All commissions of this contract will be deleted and recalculated.')
->action(function (Contract $record, array $data): void {
$record->update([
'total_commission' => $data['total_commission'],
]);

(new RecalculateCommissions())->execute($record);

Notification::make()
->title('Commissions recalculated')
->body('Commissions have been recalculated successfully.')
->success()
->send();
})
->visible(auth()->user()->hasRole(UserRole::Administrator));
Want results from more Discord servers?
Add your server