|
5 | 5 | use Illuminate\Database\Eloquent\Collection; |
6 | 6 | use Illuminate\Database\Eloquent\Model; |
7 | 7 | use Illuminate\Database\Eloquent\Model as EloquentModel; |
| 8 | +use Illuminate\Pagination\AbstractPaginator; |
8 | 9 | use Illuminate\Pagination\LengthAwarePaginator; |
9 | 10 | use Illuminate\Pagination\Paginator; |
10 | 11 | use MongoDB\BSON\ObjectID; |
@@ -264,26 +265,38 @@ protected function associateExisting($model) |
264 | 265 | return $this->setEmbedded($records); |
265 | 266 | } |
266 | 267 |
|
| 268 | + |
267 | 269 | /** |
268 | | - * Get a paginator for the "select" statement. |
269 | | - * @param int $perPage |
270 | | - * @return \Illuminate\Pagination\AbstractPaginator |
| 270 | + * @param null $perPage |
| 271 | + * @param array $columns |
| 272 | + * @param string $pageName |
| 273 | + * @param null $page |
| 274 | + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
271 | 275 | */ |
272 | | - public function paginate($perPage = null) |
| 276 | + public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) |
273 | 277 | { |
274 | 278 | $page = Paginator::resolveCurrentPage(); |
275 | 279 | $perPage = $perPage ?: $this->related->getPerPage(); |
276 | 280 |
|
277 | 281 | $results = $this->getEmbedded(); |
278 | | - |
279 | | - $total = count($results); |
280 | | - |
| 282 | + $results = $this->toCollection($results); |
| 283 | + $total = $results->count(); |
281 | 284 | $start = ($page - 1) * $perPage; |
282 | | - $sliced = array_slice($results, $start, $perPage); |
283 | 285 |
|
284 | | - return new LengthAwarePaginator($sliced, $total, $perPage, $page, [ |
285 | | - 'path' => Paginator::resolveCurrentPath(), |
286 | | - ]); |
| 286 | + $sliced = $results->slice( |
| 287 | + $start, |
| 288 | + $perPage |
| 289 | + ); |
| 290 | + |
| 291 | + return new LengthAwarePaginator( |
| 292 | + $sliced, |
| 293 | + $total, |
| 294 | + $perPage, |
| 295 | + $page, |
| 296 | + [ |
| 297 | + 'path' => Paginator::resolveCurrentPath() |
| 298 | + ] |
| 299 | + ); |
287 | 300 | } |
288 | 301 |
|
289 | 302 | /** |
|
0 commit comments