How to show error message in modal for custom Action::make()

Tables\Actions\Action::make('disburse-cash')
->label('Disburse Cash')
->icon('heroicon-o-cash')
->form([
DateTimePicker::make('date')
->label('Commission Disbursement For Date')
->withoutTime()
->required(),
])
->action(function (Merchant $record, array $data): void {
if ($data['date']) {

$transactions = $record->transactions()->whereDate('payout_time', Carbon::parse($data['date'])->toDateString())->get();

if (!$transactions->count()) {
// filament form error throw
throw new \Exception('No transactions found for the given date.');

return;
}
}
})
Tables\Actions\Action::make('disburse-cash')
->label('Disburse Cash')
->icon('heroicon-o-cash')
->form([
DateTimePicker::make('date')
->label('Commission Disbursement For Date')
->withoutTime()
->required(),
])
->action(function (Merchant $record, array $data): void {
if ($data['date']) {

$transactions = $record->transactions()->whereDate('payout_time', Carbon::parse($data['date'])->toDateString())->get();

if (!$transactions->count()) {
// filament form error throw
throw new \Exception('No transactions found for the given date.');

return;
}
}
})
Throw seems just show laravel error, but how do i show it on the Action modal itself?
6 Replies
Dennis Koch
Dennis Koch16mo ago
@elsonium Please read #✅┊rules on how to format your code
elsonium
elsoniumOP16mo ago
@Dennis Koch done sir 🫡
Dennis Koch
Dennis Koch16mo ago
Thanks. Instead of throwing an exception you can use Notifications. Here's an example. More in the notification docs.
Notification::make()
->danger()
->title('No transactions found')
->send()
Notification::make()
->danger()
->title('No transactions found')
->send()
elsonium
elsoniumOP16mo ago
@Dennis Koch thanks Dennis, is there no other way to display within the modal? maybe trigger custom validation message for the DateTime form field?
Dennis Koch
Dennis Koch16mo ago
You can either throw a Validation error or use a custom rule.
Want results from more Discord servers?
Add your server