Skip to content

Commit 0c9132c

Browse files
authored
Merge pull request #18 from OnrampLab/16-fix-not-require-field-cant-store-with-null-value
when value set to null should delete custom field value record
2 parents 4d2e00d + 9c3efc5 commit 0c9132c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Concerns/Customizable.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ public function saveCustomFieldValues(): void
100100
$customFields->each(function ($customField) use ($validatedCustomFieldValues) {
101101
if (array_key_exists($customField->key, $validatedCustomFieldValues)) {
102102
$value = $validatedCustomFieldValues[$customField->key];
103-
if (is_null($value)) {
104-
return;
105-
}
106103
$constraints = [
107104
'custom_field_id' => $customField->id,
108105
'customizable_type' => $this->getMorphClass(),
109106
'customizable_id' => $this->id
110107
];
108+
if (is_null($value)) {
109+
CustomFieldValue::where($constraints)->delete();
110+
return;
111+
}
111112
$values = ['value' => $value];
112113
CustomFieldValue::updateOrCreate($constraints, $values);
113114
}

0 commit comments

Comments
 (0)