F
Filament13mo ago
Lederp

Return error from ->action

Hi, Is it possible to return an error for example from a bulkaction->action? Almost like a validation message, my use case is I want to allow a user to select multiple table entries and extend them, but I first need to validate if they have enough balance, and alert them if not. Thanks.
Solution:
Ah wait. Forgot that you probably don’t have a form. So then I would use a notification
Jump to solution
9 Replies
Dennis Koch
Dennis Koch13mo ago
So just do your check, send a notification and return before running the actual action?! I think you could also use ->before(fn ($action) => $action->cancel())
Lederp
LederpOP13mo ago
I don't really like the idea of sending a notification and return before running the action, it feels somewhat of a dirty work around?
Dennis Koch
Dennis Koch13mo ago
Isn't that exactly what you want? Only run the action if they got the balance?
Lederp
LederpOP13mo ago
I'd like it to work almost like a validation rule, if thats possible.
Dennis Koch
Dennis Koch13mo ago
You could use a validation rule. Or a ViewField that shows the error, when you set a property on the action to true.
Lederp
LederpOP13mo ago
How do I use a validation rule within the action? Thanks Or even the second option would work too.
Solution
Dennis Koch
Dennis Koch13mo ago
Ah wait. Forgot that you probably don’t have a form. So then I would use a notification
Meymink
Meymink13mo ago
You could create a Laravel rule class (read laravel documentation on this) Add ->rule(YourRuleClass) And then do the rest of the functionality in your ->action(). This way the rule/validation is executed before performing the action. Note: you can do a validation in your rule and even display an error message in the form without customization the form.
Lederp
LederpOP13mo ago
Sadly I cannot see anyway to apply a rule to the action via ->rule I was able to do this by creating a form first, and setting rules based off that! Thanks for the guidance.
Want results from more Discord servers?
Add your server