Skip to content

Commit

Permalink
[8.x] Allow nullable columns for AsArrayObject/AsCollection casts (#3…
Browse files Browse the repository at this point in the history
…6526)

* Update AsArrayObject.php

* Update AsCollection.php

* return null

* return null

* formatting
  • Loading branch information
tomirons authored Mar 10, 2021
1 parent 12b3d57 commit b7ceae1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Casts/AsArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function castUsing(array $arguments)
return new class implements CastsAttributes {
public function get($model, $key, $value, $attributes)
{
return new ArrayObject(json_decode($attributes[$key], true));
return isset($attributes[$key]) ? new ArrayObject(json_decode($attributes[$key], true)) : null;
}

public function set($model, $key, $value, $attributes)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Casts/AsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function castUsing(array $arguments)
return new class implements CastsAttributes {
public function get($model, $key, $value, $attributes)
{
return new Collection(json_decode($attributes[$key], true));
return isset($attributes[$key]) ? new Collection(json_decode($attributes[$key], true)) : null;
}

public function set($model, $key, $value, $attributes)
Expand Down

0 comments on commit b7ceae1

Please sign in to comment.