Skip to content

Commit bf1e25a

Browse files
authored
Merge branch 'master' into pr_1745
2 parents cfe8e92 + 6cea8aa commit bf1e25a

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Jenssegers\Mongodb\Eloquent;
44

5-
use Carbon\Carbon;
5+
use Illuminate\Support\Carbon;
66
use DateTime;
77
use Illuminate\Contracts\Queue\QueueableCollection;
88
use Illuminate\Contracts\Queue\QueueableEntity;

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,36 @@ protected function associateExisting($model)
265265
}
266266

267267
/**
268-
* Get a paginator for the "select" statement.
269-
* @param int $perPage
270-
* @return \Illuminate\Pagination\AbstractPaginator
268+
* @param null $perPage
269+
* @param array $columns
270+
* @param string $pageName
271+
* @param null $page
272+
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
271273
*/
272-
public function paginate($perPage = null)
274+
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
273275
{
274-
$page = Paginator::resolveCurrentPage();
276+
$page = $page ?: Paginator::resolveCurrentPage($pageName);
275277
$perPage = $perPage ?: $this->related->getPerPage();
276278

277279
$results = $this->getEmbedded();
278-
279-
$total = count($results);
280-
280+
$results = $this->toCollection($results);
281+
$total = $results->count();
281282
$start = ($page - 1) * $perPage;
282-
$sliced = array_slice($results, $start, $perPage);
283283

284-
return new LengthAwarePaginator($sliced, $total, $perPage, $page, [
285-
'path' => Paginator::resolveCurrentPath(),
286-
]);
284+
$sliced = $results->slice(
285+
$start,
286+
$perPage
287+
);
288+
289+
return new LengthAwarePaginator(
290+
$sliced,
291+
$total,
292+
$perPage,
293+
$page,
294+
[
295+
'path' => Paginator::resolveCurrentPath()
296+
]
297+
);
287298
}
288299

289300
/**

0 commit comments

Comments
 (0)