Unique validation on edit throws error
I have a form field which have unique validation. When I am trying to update the record it throws the unique validation error. The documentation mentioned to add the
->unique(ignoreRecord: true)
but didn't helped. Anyone face this issue before? I also tried this ->unique(ignorable: fn ($record) => $record)
but same result.Solution:Jump to solution
I found what was the problem. So the $record somehow was null and that's why validated the unique every time. The workaround for this I passed the record from the Livewire component:
...
11 Replies
What's the error?
What's the whole field code?
should suffice since it checks this record only. Are you sure you don't have any other records with that value?
What if you try without spaces?
I already tried this:
->unique(ignoreRecord: true)
but still throws the error. The other records have different values.
I tried without space, it saved. Then I tried to update the record again and still throws the error.So the error is down to spaces
But the value without spaces still throws error
or what do you mean?
Ok check the queries as that deosn't make sense.
Btw, I am using this
->unique(ignorable: fn ($record) => $record)
on other places and it is working there
with and without spacesSo it works and something isn't working with your setup. Use debugbar/Telescope and view the validation request to see the query run as to what's happening
okay i will check
Solution
I found what was the problem. So the $record somehow was null and that's why validated the unique every time. The workaround for this I passed the record from the Livewire component: