Error notifications on create pages
How can I show a simple error notification when creating a resources fails? I see there is a
getCreatedNotification
but I don't see an equivalent for an error state.Solution:Jump to solution
$record
isn't available on create. You should use $state
, $get
or $livewire->data
14 Replies
I'm thinking of a case where a database unique index would be violated.
I suppose I could handle that with validation but I haven't done that with multiple columns
You can use
unique
rule or a custom rule: https://filamentphp.com/docs/3.x/forms/validation#custom-rules
You can also use hooks - https://filamentphp.com/docs/3.x/panels/resources/creating-records#halting-the-creation-processAh, hooks might be a good choice. I would use
unique
but I have 3 different fields that are used together in a unique DB index. I'm not sure how I would build a unique rule for that casemodify query in the unique method
The problem with modify query is that you can't inject the record
really? modifying query of a unique rule is in a closure, can't you get inputs state?
then do
where()->where()
in the closureI probably could chain wheres in this case but other cases I've needed
whereHas
but that isn't supported by the unique ruleit's on the create page?
Yeah
Solution
$record
isn't available on create. You should use $state
, $get
or $livewire->data
think how
$record
could be available if don't have it yet created🤦♂️