-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix attributeToArray method #3024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
678709b
6403bd8
ed5a9db
460f548
1e494b6
0bbb1ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,12 +328,22 @@ public function attributesToArray() | |
// MongoDB related objects to a string representation. This kind | ||
// of mimics the SQL behaviour so that dates are formatted | ||
// nicely when your models are converted to JSON. | ||
foreach ($attributes as $key => &$value) { | ||
$convertMongoObjects = function (&$value) use (&$convertMongoObjects) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a private method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok now is split There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the test, I simply reused existing model. Would you like me to create a new one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you can create a new model class for the test. |
||
if ($value instanceof ObjectID) { | ||
$value = (string) $value; | ||
} elseif ($value instanceof Binary) { | ||
$value = (string) $value->getData(); | ||
} elseif ($value instanceof UTCDateTime) { | ||
$value = $this->serializeDate($value->toDateTime()); | ||
} elseif (is_array($value)) { | ||
foreach ($value as &$embedValue) { | ||
$convertMongoObjects($embedValue); | ||
} | ||
} | ||
}; | ||
|
||
foreach ($attributes as $key => &$value) { | ||
$convertMongoObjects($value); | ||
} | ||
|
||
return $attributes; | ||
|
Uh oh!
There was an error while loading. Please reload this page.