Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 454c184

Browse files
Merge pull request #3 from aloware/fix/apply-model-eager-loads
Fix | Apply Model EagerLoads
2 parents c5f87ec + b87004a commit 454c184

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/CursorPaginator.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public function getQueryData($model)
174174
if ($this->cursor->getPrevCursor()) {
175175
// Converts Collection to Eloquent Collection
176176
$data = $model->hydrate($query->get($this->columns)->toArray());
177+
$data = $this->applyModelEagerLoads($data, $model);
177178
} else {
178179
$data = $query->get($this->columns);
179180
}
@@ -216,6 +217,22 @@ public function resolveCurrentCursor()
216217
return $cursor;
217218
}
218219

220+
/**
221+
* Applies model eagerLoads to the new collection
222+
* @param Collection $data
223+
* @param Model $model
224+
*
225+
* @return Collection
226+
*/
227+
public function applyModelEagerLoads($data, $model)
228+
{
229+
foreach ($model->getEagerLoads() as $key=>$eagerLoad) {
230+
$data->load($key);
231+
}
232+
233+
return $data;
234+
}
235+
219236
/**
220237
* Set the items for the paginator.
221238
*

0 commit comments

Comments
 (0)