[1.0.2] Undefined array key "rut"
noquierouser opened this issue · 3 comments
PHP & Platform
8.1.3
Laravel verion
9.3.0
Have you done this?
- I am willing to share my stack trace and logs
- I can reproduce this bug in isolation (vanilla Laravel install)
- I can suggest a workaround as a Pull Request
Expectation
Livewire validation passes (or fails) the rut
property/cast if a model uses the HasRut
trait.
Description
Laravel/Livewire returns a ErrorException
indicating Undefined array key "rut"
when attempting real-time validation ($this->validateOnly()
), and clears the <rut>
input field when the $this->validate()
method is executed on form submit.
Reproduction
// https://github.com/noquierouser/laragear-rut-livewire-bug
Stack trace & logs
No response
Are you a Patreon supporter?
No, don't give priority to this
It appears that Livewire retrieves a 'rut_num' and 'rut_vd' keys instead of 'rut' keys. I assume this is retrieved from the model itself.
There is a chance there is nothing I can do and the bug should be remitted to Livewire repo instead.
I'm still investigating.
Okay, the cause of this is because, when Livewire retrieves the list of attributes from the Model to infuse with the validated data, it believes the validated rut
attribute is on the Model rut
attributes. This is not the case.
This is easily fixed using $appends = ['rut']
to the model.
I'm adding two fixes. One for the validation rule to use parse
instead of check, and another to automatically append the rut
and hide the rut_num
and rut_vd
from serialization.
Ensure you're appending the rut
.