File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,29 @@ public function customFieldResponses()
18
18
}
19
19
20
20
/**
21
- * Save the given custom fields to the model.
21
+ * Save the custom fields to the model.
22
+ * This parameter accepts a list of fields for immediate saving & backwards compatibility.
22
23
*
23
24
* @param $fields
24
25
*/
25
- public function saveCustomFields ($ fields )
26
+ public function saveCustomFields ($ fields = [])
27
+ {
28
+ if (!empty ($ fields )) {
29
+ $ this ->makeCustomFields ($ fields );
30
+ }
31
+
32
+ $ this ->customFieldResponses ->each (function (CustomFieldResponse $ field ) {
33
+ $ field ->model_id ??= $ this ->id ; // set the ID now, if model did not exist when makeCustomFields() was called
34
+ $ field ->save ();
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Make the given custom fields but do not save.
40
+ *
41
+ * @param $fields
42
+ */
43
+ public function makeCustomFields ($ fields )
26
44
{
27
45
foreach ($ fields as $ key => $ value ) {
28
46
$ customField = CustomField::find ((int ) $ key );
@@ -38,7 +56,7 @@ public function saveCustomFields($fields)
38
56
'model_type ' => get_class ($ this ),
39
57
]);
40
58
41
- $ customFieldResponse -> save ( );
59
+ $ this -> customFieldResponses -> push ( $ customFieldResponse );
42
60
}
43
61
}
44
62
You can’t perform that action at this time.
0 commit comments