Level 37
Well maybe take a different approach (which I see as a better approach).
Define an accessor that does the casting each time you get the column, and you can do more stuff with it
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone! So i jumped into a problem that defines a datetime in nested column in mongoDB Laravel.
Example in Docs
protected $casts = [
'created_at' => 'datetime',
];
My data
$data->attribute_list = [
"Battery" = [
"value" = 3.98,
"read_time" = Carbon::now(),
"received_time" = Carbon::now()
],
$data->save();
i tried to do the cast like this, but it returns null
protected $casts = [
'attribute_list.*.read_time' => 'datetime',
'attribute_list.*.received_time' => 'datetime',
];
How to achieve that?
Please or to participate in this conversation.