|
9 | 9 | use Illuminate\Support\Arr;
|
10 | 10 | use Illuminate\Support\Str;
|
11 | 11 | use Jenssegers\Mongodb\Query\Builder as QueryBuilder;
|
| 12 | +use MongoDB\BSON\Binary; |
12 | 13 | use MongoDB\BSON\ObjectID;
|
13 | 14 | use MongoDB\BSON\UTCDateTime;
|
14 | 15 | use Illuminate\Contracts\Queue\QueueableEntity;
|
@@ -63,6 +64,8 @@ public function getIdAttribute($value = null)
|
63 | 64 | // Convert ObjectID to string.
|
64 | 65 | if ($value instanceof ObjectID) {
|
65 | 66 | return (string) $value;
|
| 67 | + } elseif ($value instanceof Binary) { |
| 68 | + return (string) $value->getData(); |
66 | 69 | }
|
67 | 70 |
|
68 | 71 | return $value;
|
@@ -172,7 +175,7 @@ protected function getAttributeFromArray($key)
|
172 | 175 | public function setAttribute($key, $value)
|
173 | 176 | {
|
174 | 177 | // Convert _id to ObjectID.
|
175 |
| - if ($key == '_id' && is_string($value)) { |
| 178 | + if (($key == '_id' || Str::endsWith($key, '_id')) && is_string($value)) { |
176 | 179 | $builder = $this->newBaseQueryBuilder();
|
177 | 180 |
|
178 | 181 | $value = $builder->convertKey($value);
|
@@ -204,6 +207,8 @@ public function attributesToArray()
|
204 | 207 | foreach ($attributes as $key => &$value) {
|
205 | 208 | if ($value instanceof ObjectID) {
|
206 | 209 | $value = (string) $value;
|
| 210 | + } elseif ($value instanceof Binary) { |
| 211 | + $value = (string) $value->getData(); |
207 | 212 | }
|
208 | 213 | }
|
209 | 214 |
|
|
0 commit comments