Carbon error: Data object from model with relationship #91
-
Imagine the following structure: App has class ClientData extends Data
{
public function __construct(
public ?int $id,
public ?Carbon $created_at,
public ?Carbon $updated_at,
)
{
}
} class UserData extends Data
{
public function __construct(
public int $id,
public ?ClientData $client,
public ?Carbon $created_at,
public ?Carbon $updated_at,
)
{
}
} It is necessary to display a collection of UserData::collection(User::with('client')->paginate()); But, I got error:
Here's why it's happening:
[
...
"created_at" => Illuminate\Support\Carbon
"client" => [
...
"created_at" => "2022-02-07T10:49:26.000000Z"
]
] As you can see, the model attribute That is the problem. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Same here. I spent a few hours with this. I assume that nested relations are somehow normalized to arrays. So that means Carbon objects in Laravel models are serialized to strings with Carbon´s toIsoString() method. Does this help? |
Beta Was this translation helpful? Give feedback.
-
Hi all, This should be fixed with the release later today! 0c79a3b |
Beta Was this translation helpful? Give feedback.
-
apparently this is happening again.
|
Beta Was this translation helpful? Give feedback.
-
This work for me |
Beta Was this translation helpful? Give feedback.
Same here. I spent a few hours with this. I assume that nested relations are somehow normalized to arrays. So that means Carbon objects in Laravel models are serialized to strings with Carbon´s toIsoString() method. Does this help?
#[WithCast(DateTimeInterfaceCast::class, format: "Y-m-d\TH:i:s.u\Z")]