Exceptions from Model

Hi, how are you handling when you submit a Filament form, and the Model has a saving function that blocks the saving?? For example, I trigger a ValidationException in the saving function (Model), and Filament doesn't show any alert or message
10 Replies
ffffer.
ffffer.OP3mo ago
No one handles Model exceptions?
dissto
dissto3mo ago
Have you enabled database transactions ? Or maybe (additionally?) in combination with ->failureNotificationTitle('Whoops') on the given action 🤔
Dennis Koch
Dennis Koch3mo ago
I never validated anything in my model. I think the data should be validated before.
ffffer.
ffffer.OP2mo ago
And when you have validations in both controllers and filament panel? Two different validations?
awcodes
awcodes2mo ago
What is the use case of 2 different validations.? I could be wrong but the db can only store one type per field.
ffffer.
ffffer.OP2mo ago
User signup (api controller) and register user through panel (not admin, website user). Or any other situation where you have api controller and panel resource doing the same
awcodes
awcodes2mo ago
But the data is the same right? So just create a set of validation rules that can be plugged into both places. It’s still just an array of validation rules. But, that could still just be a static method on the model that returns the array.
drabew
drabew2mo ago
But plug-in external validator (e.g. class that returns array of validation rules) into whole Filament form is not possible, so using the same validation rules between diffrent entrypoints (filament, api, external form) can be quite tricky.
ffffer.
ffffer.OP2mo ago
Exactly, that's what I mean, and I like to rely on the Model validation, that's should be extended to Filament, but Filament is not reporting feedback about the validation on the Model
drabew
drabew2mo ago
Probably you can overwrite getValidationRules() in CreateRecord/EditRecord class and handle there own logic for validation logic.

Did you find this page helpful?