Laragear / Rut

Gracefully handle RUTs from within your Laravel application
https://patreon.com/packagesforlaravel
MIT License
6 stars 0 forks source link

[1.0.2] Undefined array key "rut" #5

Closed noquierouser closed 2 years ago

noquierouser commented 2 years ago

PHP & Platform

8.1.3

Laravel verion

9.3.0

Have you done this?

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

DarkGhostHunter commented 2 years ago

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.

DarkGhostHunter commented 2 years ago

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.

DarkGhostHunter commented 2 years ago

Fixed in 1.1.0.

Ensure you're appending the rut.