Replies: 3 comments 4 replies
-
Having the same issue of livewire converting the property to an array. Interestingly, it only seems to happen on nested livewire components. |
Beta Was this translation helpful? Give feedback.
-
That's how it worked in v2, but this breaks nested validation, long read: (https://flareapp.io/blog/47-fixing-nested-validation-in-laravel)
You're always welcome to send in a tested + documented PR
Not sure if we can do anything about that, LiveWire has a lot of magic we can't work arround. @francoism90, if I'm not mistaken you're a bit the laravel-data with Livewire expert, maybe you can help? |
Beta Was this translation helpful? Give feedback.
-
The main problem of my usage of Livewire is the |
Beta Was this translation helpful? Give feedback.
-
I'm using a data object in a complex livewire cart.
I saw a lot of limitations to using it and the documentation has a huge lack of information.
So I wrote this post to explain how I used it and to encourage a discussion.
For example purposes I use a
Cart
livewire controller, aCartItemData
with a nestedDataCollection
ofCartItemLicenseData
:1) Rules
After a lot o tries I can reuse the rules defined on Data Class Validation Attributes with this implementation:
The problem is the nested DataCollection object inside
CartItemData
that returns aIlluminate\Validation\NestedRules
So I need to create rules of nested objects myself using these functions
But I think
getValidationRules()
or a newrules()
method must return a complete set of rules without having a parameter to pass on that.2) Validation Attributes and Validation Message
Like
getValidationRules()
the package should have agetValidationAttributes()
andgetValidationMessages()
that return recursively all attributes and messages from data objects and its nested objects.For now, I have to create a function like this:
3) Rerendering page and Data manipulation needs a recreation of the Data Object
On the first render of the cart, the
$item
has aCartItemData
type, but when I call a livewire function from the cart,I need to reinitialize it with this function:
because livewire transforms the object into an array.
And on the
render
function I need to reinitialize all the array items for every page rendering:There is a better approach to using Laravel-data on Livewire?
Beta Was this translation helpful? Give feedback.
All reactions