Skip to content

Commit 9e4d3d1

Browse files
Allows setting null values.
1 parent 7ae0fc9 commit 9e4d3d1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ public function get($model, $key, $value, $attributes)
5050

5151
public function set($model, $key, $value, $attributes)
5252
{
53-
if (! isset($attributes[$key])) {
54-
return;
53+
if (! is_null($value)) {
54+
return [
55+
$key => match(true) {
56+
$value instanceof Jsonable => $value->toJson(),
57+
$value instanceof Arrayable => Json::encode($value->toArray()),
58+
default => throw new ValueError(sprintf(
59+
'The %s class should implement Jsonable or Arrayable contract.', $this->class)
60+
)
61+
}
62+
];
5563
}
5664

57-
return [
58-
$key => match(true) {
59-
$value instanceof Jsonable => $value->toJson(),
60-
$value instanceof Arrayable => Json::encode($value->toArray()),
61-
default => throw new ValueError(sprintf(
62-
'The %s class should implement Jsonable or Arrayable contract.', $this->class)
63-
)
64-
}
65-
];
65+
return null;
6666
}
6767
};
6868
}

0 commit comments

Comments
 (0)