@@ -36,10 +36,10 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
36
36
protected static $ resolver ;
37
37
38
38
/**
39
- * Convert a DateTime to a storable string .
39
+ * Convert a DateTime to a storable MongoDate object .
40
40
*
41
41
* @param DateTime|int $value
42
- * @return string
42
+ * @return MongoDate
43
43
*/
44
44
public function fromDateTime ($ value )
45
45
{
@@ -66,11 +66,13 @@ public function fromDateTime($value)
66
66
*/
67
67
protected function asDateTime ($ value )
68
68
{
69
+ // Convert MongoDate to timestamp
69
70
if ($ value instanceof MongoDate)
70
71
{
71
72
$ value = $ value ->sec ;
72
73
}
73
74
75
+ // Convert timestamp to string for DateTime
74
76
if (is_int ($ value ))
75
77
{
76
78
$ value = "@ $ value " ;
@@ -82,7 +84,7 @@ protected function asDateTime($value)
82
84
/**
83
85
* Get a fresh timestamp for the model.
84
86
*
85
- * @return DateTime
87
+ * @return MongoDate
86
88
*/
87
89
public function freshTimestamp ()
88
90
{
@@ -195,13 +197,13 @@ public function setRawAttributes(array $attributes, $sync = false)
195
197
{
196
198
foreach ($ attributes as $ key => &$ value )
197
199
{
198
- // Convert MongoId
200
+ // Convert MongoId to string
199
201
if ($ value instanceof MongoId)
200
202
{
201
203
$ value = (string ) $ value ;
202
204
}
203
205
204
- // Convert MongoDate
206
+ // Convert MongoDate to string
205
207
else if ($ value instanceof MongoDate)
206
208
{
207
209
$ value = $ this ->asDateTime ($ value )->format ('Y-m-d H:i:s ' );
0 commit comments