Skip to content

Commit 2ef0fa9

Browse files
committed
Update DocumentModel.php;
1 parent 21d4d28 commit 2ef0fa9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Eloquent/DocumentModel.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Contracts\Queue\QueueableCollection;
1212
use Illuminate\Contracts\Queue\QueueableEntity;
1313
use Illuminate\Contracts\Support\Arrayable;
14+
use Illuminate\Database\Eloquent\Casts\Json;
1415
use Illuminate\Database\Eloquent\Concerns\HasAttributes;
1516
use Illuminate\Database\Eloquent\Model;
1617
use Illuminate\Database\Eloquent\Relations\Relation;
@@ -266,6 +267,16 @@ public function setAttribute($key, $value)
266267
return parent::setAttribute($key, $value);
267268
}
268269

270+
/** @inheritdoc */
271+
protected function isJsonCastable($key)
272+
{
273+
if ($this->hasCast($key, ['array'])) {
274+
return false;
275+
}
276+
277+
return parent::isJsonCastable($key);
278+
}
279+
269280
/**
270281
* @param mixed $value
271282
*
@@ -287,6 +298,15 @@ protected function asDecimal($value, $decimals)
287298
return parent::asDecimal($value, $decimals);
288299
}
289300

301+
public function fromJson($value, $asObject = false)
302+
{
303+
if (is_array($value)) {
304+
return $value;
305+
}
306+
307+
return parent::fromJson($value, $asObject);
308+
}
309+
290310
/**
291311
* Change to mongo native for decimal cast.
292312
*

0 commit comments

Comments
 (0)