Skip to content

Commit

Permalink
Check if attribute relation is loaded when resolving attribute value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokfk authored Feb 21, 2022
1 parent a5d9ba0 commit 9165ca6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/NovaBelongsToDepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ public function resolve($resource, $attribute = null)
$foreign = $resource->{$this->attribute}();
$this->foreignKeyName = $foreign->getForeignKeyName();

$value = $resource->{$this->attribute}()->withoutGlobalScopes()->first();
if ($resource->relationLoaded($this->attribute)) {
$value = $resource->getRelation($this->attribute);
} else {
$value = $resource->{$this->attribute}()->withoutGlobalScopes()->first();
}

if ($value) {
$this->valueKey = $value->getKey();
$this->value = $this->formatDisplayValue($value);
Expand Down

0 comments on commit 9165ca6

Please sign in to comment.