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
cwilby authored Apr 12, 2021
1 parent 8423628 commit 69a23f7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/NovaBelongsToDepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 69a23f7

Please sign in to comment.