From 5ece8fe6e92b85ad6c0bf86da1356aff274cde88 Mon Sep 17 00:00:00 2001 From: Haider Ali Date: Tue, 11 Jan 2022 19:34:20 +0500 Subject: [PATCH] Fix details screen issue when using belongs to relation. e,g 'role.id' --- src/NovaDependencyContainer.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/NovaDependencyContainer.php b/src/NovaDependencyContainer.php index e8157e3..e5ff3b9 100644 --- a/src/NovaDependencyContainer.php +++ b/src/NovaDependencyContainer.php @@ -123,9 +123,11 @@ public function dependsOnNullOrZero($field) */ protected function getFieldLayout($field, $value = null) { + $resourceContext = 'relation'; if (count( ($field = explode('.', $field)) ) === 1) { // backwards compatibility, property becomes field $field[1] = $field[0]; + $resourceContext = 'parent'; } return [ // literal form input name @@ -134,6 +136,8 @@ protected function getFieldLayout($field, $value = null) 'property' => $field[1], // value to compare 'value' => $value, + // context to compare (field parent resource or relation resource) + 'context' => $resourceContext, ]; } @@ -174,10 +178,14 @@ public function resolveForDisplay($resource, $attribute = null) } if (array_key_exists('value', $dependency)) { - if ($dependency['value'] == $resource->{$dependency['property']}) { + if ($dependency['context'] === 'parent' && $dependency['value'] == $resource->{$dependency['property']}) { + $this->meta['dependencies'][$index]['satisfied'] = true; + continue; + } elseif ($dependency['value'] == optional($resource->{$dependency['field']})->{$dependency['property']}) { $this->meta['dependencies'][$index]['satisfied'] = true; continue; } + // @todo: quickfix for MorphTo $morphable_attribute = $resource->getAttribute($dependency['property'].'_type'); if ($morphable_attribute !== null && Str::endsWith($morphable_attribute, '\\'.$dependency['value'])) {