It would be great to have custom fields, depending on specific conditions.
Here is a nasty draft working proof of concept :
CustomFieldsTrait , getCustomFieldGroups method :
//filter on display_if_property and display_if_value
$customFieldGroup->customField = $customFieldGroup->customField->filter(function ($customField) {
if (!empty($customField->display_if_property) && !empty($customField->display_if_value)) {
if ($this->{$customField->display_if_property} == $customField->display_if_value) {
return $customField;
}
}
else {
return $customField;
}
});
getCustomFieldsData method after $data = collect($data); :
foreach($data as $key => $field) { //var_dump(CustomField::find(preg_replace('/field_/','',$field->field_id))->toArray());
$display_if_property=CustomField::find(preg_replace('/field_/','',$field->field_id))->display_if_property??'';
$display_if_value=CustomField::find(preg_replace('/field_/','',$field->field_id))->display_if_value??'';
if (!empty($display_if_property )) {
if( $this->{$display_if_property} != $display_if_value) {// var_dump($key); die();
$data->forget($key);
}
}
}
==
i then simply added display_if_property and display_if_value in custom fields addition form.
As a result, i can add fields depending on if product category_id is 1 or 2 for example.