"Property type not supported in Livewire for property" when using custom casts
I have a json field on my model, where I use a custom class as a cast:
This fields contains only 3 properties and I am displaying the form like this:
This worked in v2 without any problems, now in v3 I get an error:
The
HotelText
implements the implements CastsAttributes, ArrayAccess
interfaces. When changing the cast to array
, it works as well.
Any ideas to get around this?7 Replies
Encountered the same problem today with code I ported from v2, seems to be a livewire issue
For now I just removed my custom casts
Try making your custom cast class Wireable:
https://livewire.laravel.com/docs/properties#wireables
Laravel
Properties | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
You'll need to read the whole Properties page to understand what's happening and why LW doesn't understand your type, and you could consider using a Synthesizer, although that's probably overkill:
https://livewire.laravel.com/docs/synthesizers
Laravel
Synthesizers | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
TL/DR, Livewire 3 needs to know how to convert any property to and from JSON. It has built in support for all the common datatypes, but if you need to wire.model a custom class, you need to make it Wireable, with toLivewire and fromLivewire methods, so LW knows what to do with it.
Thanks. I implemented
Wireable
and now the form is showing, but on save I get
Its not an option for me, for now, since I have implmented some methods I use on the cast classesYou may need a synthesizer. I would have thought simply making it wireable would work, but I'm still a little hazy on the difference.
Synthesizers aren't hard, though, and are well documented.
Thanks!