Skip to content

Commit 678709b

Browse files
fix attributeToArray method
1 parent 8333880 commit 678709b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Eloquent/Model.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,20 @@ public function attributesToArray()
328328
// MongoDB related objects to a string representation. This kind
329329
// of mimics the SQL behaviour so that dates are formatted
330330
// nicely when your models are converted to JSON.
331-
foreach ($attributes as $key => &$value) {
331+
$convertMongoObjects = function (&$value) use (&$convertMongoObjects) {
332332
if ($value instanceof ObjectID) {
333333
$value = (string) $value;
334334
} elseif ($value instanceof Binary) {
335335
$value = (string) $value->getData();
336+
} elseif (is_array($value)) {
337+
foreach ($value as &$embedValue) {
338+
$convertMongoObjects($embedValue);
339+
}
336340
}
341+
};
342+
343+
foreach ($attributes as $key => &$value) {
344+
$convertMongoObjects($value);
337345
}
338346

339347
return $attributes;

0 commit comments

Comments
 (0)