Skip to content

Commit b7ceae1

Browse files
authored
[8.x] Allow nullable columns for AsArrayObject/AsCollection casts (#36526)
* Update AsArrayObject.php * Update AsCollection.php * return null * return null * formatting
1 parent 12b3d57 commit b7ceae1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Illuminate/Database/Eloquent/Casts/AsArrayObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function castUsing(array $arguments)
1818
return new class implements CastsAttributes {
1919
public function get($model, $key, $value, $attributes)
2020
{
21-
return new ArrayObject(json_decode($attributes[$key], true));
21+
return isset($attributes[$key]) ? new ArrayObject(json_decode($attributes[$key], true)) : null;
2222
}
2323

2424
public function set($model, $key, $value, $attributes)

src/Illuminate/Database/Eloquent/Casts/AsCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function castUsing(array $arguments)
1919
return new class implements CastsAttributes {
2020
public function get($model, $key, $value, $attributes)
2121
{
22-
return new Collection(json_decode($attributes[$key], true));
22+
return isset($attributes[$key]) ? new Collection(json_decode($attributes[$key], true)) : null;
2323
}
2424

2525
public function set($model, $key, $value, $attributes)

0 commit comments

Comments
 (0)