Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
[Fix] AbstractEloquentResource: account for absence of related model …
Browse files Browse the repository at this point in the history
…for singular relationships.
  • Loading branch information
Jeffrey Westerkamp authored and Coen Zimmerman committed Sep 20, 2017
1 parent 70d3ef2 commit 8144db2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Support/Resource/AbstractEloquentResource.php
Expand Up @@ -152,7 +152,18 @@ public function relationshipReferences($include)
}

if ($this->model->relationLoaded($method)) {
$ids = $this->model->{$method}->pluck($relatedModel->getKeyName())->toArray();
if ($singular) {

if ($this->model->{$method}) {
$ids = [ $this->model->{$method}->{$relatedModel->getKeyName()} ];
} else {
$ids = [];
}

} else {
$ids = $this->model->{$method}->pluck($relatedModel->getKeyName())->toArray();
}

} else {
$ids = $relation->pluck($relatedModel->getQualifiedKeyName())->toArray();
}
Expand Down

0 comments on commit 8144db2

Please sign in to comment.