diff options
Diffstat (limited to 'vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php')
| -rwxr-xr-x | vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php b/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php index d502897510..2eebe42113 100755 --- a/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php +++ b/vendor/illuminate/database/Eloquent/Relations/BelongsToMany.php @@ -559,7 +559,9 @@ class BelongsToMany extends Relation */ public function getResults() { - return $this->get(); + return ! is_null($this->parent->{$this->parentKey}) + ? $this->get() + : $this->related->newCollection(); } /** @@ -679,6 +681,32 @@ class BelongsToMany extends Relation } /** + * Chunk the results of a query by comparing numeric IDs. + * + * @param int $count + * @param callable $callback + * @param string|null $column + * @param string|null $alias + * @return bool + */ + public function chunkById($count, callable $callback, $column = null, $alias = null) + { + $this->query->addSelect($this->shouldSelect()); + + $column = $column ?? $this->getRelated()->qualifyColumn( + $this->getRelatedKeyName() + ); + + $alias = $alias ?? $this->getRelatedKeyName(); + + return $this->query->chunkById($count, function ($results) use ($callback) { + $this->hydratePivotRelation($results->all()); + + return $callback($results); + }, $column, $alias); + } + + /** * Execute a callback over each item while chunking. * * @param callable $callback |
