Skip to content

Commit 6ec9573

Browse files
committed
Manual merge of #487
1 parent db0c952 commit 6ec9573

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ public function attributesToArray()
336336
}
337337
}
338338

339+
// Convert dot-notation dates.
340+
foreach ($this->getDates() as $key)
341+
{
342+
if (str_contains($key, '.') and array_has($attributes, $key))
343+
{
344+
array_set($attributes, $key, (string) $this->asDateTime(array_get($attributes, $key)));
345+
}
346+
}
347+
339348
return $attributes;
340349
}
341350

tests/ModelTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ public function testDates()
402402

403403
$user->setAttribute('entry.date', new DateTime);
404404
$this->assertInstanceOf('Carbon\Carbon', $user->getAttribute('entry.date'));
405+
406+
$data = $user->toArray();
407+
$this->assertNotInstanceOf('MongoDate', $data['entry']['date']);
408+
$this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']);
405409
}
406410

407411
public function testIdAttribute()

0 commit comments

Comments
 (0)