diff --git a/src/NovaBelongsToDepend.php b/src/NovaBelongsToDepend.php index 9a75ea6..80d5e70 100644 --- a/src/NovaBelongsToDepend.php +++ b/src/NovaBelongsToDepend.php @@ -135,8 +135,15 @@ public function resolve($resource, $attribute = null) $this->dependKey = $resource->{$this->dependsOn}()->getForeignKeyName(); } - $value = $resource->{$this->attribute}()->withoutGlobalScopes()->first(); - if ($value) { + if ($resource->relationLoaded($this->attribute)) { + $value = $resource->getRelation($this->attribute); + } + + if (empty($value)) { + $value = $resource->{$this->attribute}()->withoutGlobalScopes()->getResults(); + } + + if (!empty($value)) { $this->valueKey = $value->getKey(); $this->value = $this->formatDisplayValue($value); }