Skip to content

Commit

Permalink
Update HasMany.php
Browse files Browse the repository at this point in the history
Update setPassOnKeys only on an API resource
  • Loading branch information
colinhall17 committed Aug 4, 2020
1 parent ae87dee commit 4c7e075
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Support/Relations/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ public function last()

public function getRelationFromApi()
{
$this->relation = $this->newRelation($this->updateFields([]))->setPassOnAttributes($this->getUpdateKeys())->all();
if(method_exists($relation = $this->newRelation($this->updateFields([])), 'setPassOnAttributes')) {
$this->relation = $relation->setPassOnAttributes($this->getUpdateKeys())->all();
}
if($this->hasUpdateFields()){
foreach($this->relation as $object){
$this->updateFields($object);
Expand Down Expand Up @@ -201,7 +203,10 @@ public function __call($method, $parameters)
if($this->relation->count() > 0 && method_exists($this->relation, $method)){
return $this->forwardCallTo($this->relation, $method, $parameters);
} else {
$relation = $this->newRelation($this->updateFields([]))->setPassOnAttributes($this->getUpdateKeys());
$relation = $this->newRelation($this->updateFields([]));
if(method_exists($relation, 'setPassOnAttributes')){
$relation->setPassOnAttributes($this->getUpdateKeys());
}
return $this->forwardCallTo($relation, $method, $parameters);
}
}
Expand Down

0 comments on commit 4c7e075

Please sign in to comment.