Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 266ce44

Browse files
committed
Relations eager loading support when paginating
1 parent 067d0b1 commit 266ce44

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/Builders/FilterBuilder.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,34 @@ public function from($offset)
205205

206206
return $this;
207207
}
208+
209+
/**
210+
* @inheritdoc
211+
*/
212+
public function get()
213+
{
214+
$collection = parent::get();
215+
216+
if (isset($this->with) && $collection->count() > 0) {
217+
$collection->load($this->with);
218+
}
219+
220+
return $collection;
221+
}
222+
223+
/**
224+
* @inheritdoc
225+
*/
226+
public function paginate($perPage = null, $pageName = 'page', $page = null)
227+
{
228+
$paginator = parent::paginate($perPage, $pageName, $page);
229+
230+
if (isset($this->with) && $paginator->total() > 0) {
231+
$paginator
232+
->getCollection()
233+
->load($this->with);
234+
}
235+
236+
return $paginator;
237+
}
208238
}

src/ElasticEngine.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,4 @@ public function getTotalCount($results)
225225
{
226226
return $results['hits']['total'];
227227
}
228-
229-
/**
230-
* @inheritdoc
231-
*/
232-
public function get(Builder $builder)
233-
{
234-
$collection = parent::get($builder);
235-
236-
if (isset($builder->with) && $collection->count() > 0) {
237-
$collection->load($builder->with);
238-
}
239-
240-
return $collection;
241-
}
242228
}

0 commit comments

Comments
 (0)