"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:
protected $casts = [
"hotel_texts" => HotelText::class,
];
protected $casts = [
"hotel_texts" => HotelText::class,
];
This fields contains only 3 properties and I am displaying the form like this:
TextInput::make("hotel_texts.field1"),
TextInput::make("hotel_texts.field2"),
TextInput::make("hotel_texts.field3"),
TextInput::make("hotel_texts.field1"),
TextInput::make("hotel_texts.field2"),
TextInput::make("hotel_texts.field3"),
This worked in v2 without any problems, now in v3 I get an error:
Property type not supported in Livewire for property: [{"field1":"..
Property type not supported in Livewire for property: [{"field1":"..
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
josef
josef17mo ago
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
cheesegrits
cheesegrits17mo ago
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.
cheesegrits
cheesegrits17mo ago
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.
cheesegrits
cheesegrits17mo ago
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.
bernhard
bernhardOP16mo ago
Thanks. I implemented Wireable and now the form is showing, but on save I get
This synth doesn't support setting properties: Livewire\Features\SupportWireables\WireableSynth
This synth doesn't support setting properties: Livewire\Features\SupportWireables\WireableSynth
Its not an option for me, for now, since I have implmented some methods I use on the cast classes
cheesegrits
cheesegrits16mo ago
You 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.
bernhard
bernhardOP16mo ago
Thanks!
Want results from more Discord servers?
Add your server