Closed mikebronner closed 5 months ago
Thanks, Mike. It shouldn't be an issue. Accessing attributes on Eloquence models converts all calls to attributes to snake_case when it tries to access an attribute. It doesn't maintain its own internal casing, so it's a weird bug. If you can find out more info, that'd be great (also a big livewire fan).
A bit more context:
Livewire validations:
protected function rules(): array
{
return [
"paymentProcessGroup.processor_settings.authorize-dot-net-login-id" => "string|nullable",
];
}
For it to work, it must be written in camel case:
protected function rules(): array
{
return [
"paymentProcessGroup.processorSettings.authorize-dot-net-login-id" => "string|nullable",
];
}
Here's a snippet of the model (it inherits the camel-casing trat from a parent model)
class PaymentProcessGroup
{
protected $casts = [
"processor_settings" => "array",
];
}
Maybe this will help ring a bell?
@kirkbushell Diving into Livewire's validation code, it appears they convert everything that gets validated to arrays by calling toArray()
on models and collections. The CamelCase trait exposes only the camel-cased properties. Would it be a bad thing to expose both the snake-cased as well as the camel-cased properties via toArray()
or would that cause issues?
I mean, it would probably mess with anyone trying to iterate over the array, so not quite sure what the best solution is here? What do you think?
@mikebronner Have you tried doing the casting as a camelCase value instead?
The point of the camelCase trait is to use camelCasing wherever you're working with model fields.
I didn't ... do you write all your fillable, casts, etc. in camel-case? I didn't realize that the camel casing trait would allow for that.
I didn't ... do you write all your fillable, casts, etc. in camel-case? I didn't realize that the camel casing trait would allow for that.
You shouldn't have to, the point of the library is to convert to-from snake_case, as this is the default mode when reading from the database. I was asking in case maybe that resolved it :)
More than likely I need to add better support for casts.
@mikebronner right, gonna properly support casts in 11.0.
@mikebronner should now be fully supported in v11.
When trying to access data in json attributes in models, Livewire is unable to access the snake-case format, which makes it problematic if you are in a transition period between moving from snake_case to camelCase.
I haven't dug into this yet to see how Livewire accesses model properties, but I'll try and give it a go and submit a PR if I can.