From 9f8bae685916881a5cdc5136a7e0e4c7a49f2c9e Mon Sep 17 00:00:00 2001 From: Colin Hall Date: Fri, 29 May 2020 15:09:10 +0100 Subject: [PATCH] fix make on hasMany --- src/Support/Relations/HasMany.php | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Support/Relations/HasMany.php b/src/Support/Relations/HasMany.php index c948cea..63e5e08 100644 --- a/src/Support/Relations/HasMany.php +++ b/src/Support/Relations/HasMany.php @@ -25,7 +25,7 @@ public function __construct($related, $owner, $name, $field, $updateFields = []) $this->boot(); } - protected function setUpdateFields($fields) + protected function setUpdateFields($fields) { $this->updateFields = $fields; if($this->owner->hasKey()){ @@ -33,12 +33,12 @@ protected function setUpdateFields($fields) } } - public function hasUpdateFields() + public function hasUpdateFields() { return $this->updateFields != []; } - public function getUpdateKeys() + public function getUpdateKeys() { return array_keys($this->updateFields); } @@ -56,7 +56,7 @@ public function updateFields($item){ return $item; } - public function boot() + public function boot() { if(array_key_exists($this->name, $this->owner->getAttributes())){ $this->hydrate($this->owner->getAttributes()[$this->name]); @@ -75,7 +75,7 @@ public function boot() } } - protected function hydrate($array) + protected function hydrate($array) { $collection = new Collection; if($array != []){ @@ -86,7 +86,7 @@ protected function hydrate($array) $this->relation = $collection; } - public function empty() + public function empty() { $this->relation = new Collection; return $this; @@ -94,7 +94,7 @@ public function empty() public function make($data) { - $this->attach($this->newRelation($this->updateFields($data))); + $this->attach(($object = $this->newRelation($this->updateFields($data)))); return $object; } @@ -106,7 +106,7 @@ public function attach($object) public function detach($object) { - + } public function save(object $object) @@ -140,25 +140,25 @@ public function createMany(array $data) return $this; } - public function getResults() + public function getResults() { if($this->relation->count() == 0){ $this->getRelationFromApi(); - } + } return $this->relation; } - public function first() + public function first() { return $this->getResults()->first()->fresh(); } - public function last() + public function last() { return $this->getResults()->last()->fresh(); } - public function getRelationFromApi() + public function getRelationFromApi() { $this->relation = $this->newRelation($this->updateFields([]))->setPassOnAttributes($this->getUpdateKeys())->all(); if($this->hasUpdateFields()){ @@ -169,7 +169,7 @@ public function getRelationFromApi() return $this; } - public function nextPage() + public function nextPage() { $this->relation = $this->relation->nextPage(); if($this->hasUpdateFields()){ @@ -179,7 +179,7 @@ public function nextPage() } } - public function prevPage() + public function prevPage() { $this->relation = $this->relation->prevPage(); if($this->hasUpdateFields()){ @@ -203,9 +203,9 @@ public function __call($method, $parameters) } else { $relation = $this->newRelation($this->updateFields([]))->setPassOnAttributes($this->getUpdateKeys()); return $this->forwardCallTo($relation, $method, $parameters); - } + } } // Be good to add these:- findOrNew, firstOrNew, firstOrCreate and updateOrCreate -} \ No newline at end of file +}