@@ -265,25 +265,36 @@ protected function associateExisting($model)
265
265
}
266
266
267
267
/**
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
271
273
*/
272
- public function paginate ($ perPage = null )
274
+ public function paginate ($ perPage = null , $ columns = [ ' * ' ], $ pageName = ' page ' , $ page = null )
273
275
{
274
- $ page = Paginator::resolveCurrentPage ();
276
+ $ page = $ page ?: Paginator::resolveCurrentPage ($ pageName );
275
277
$ perPage = $ perPage ?: $ this ->related ->getPerPage ();
276
278
277
279
$ results = $ this ->getEmbedded ();
278
-
279
- $ total = count ($ results );
280
-
280
+ $ results = $ this ->toCollection ($ results );
281
+ $ total = $ results ->count ();
281
282
$ start = ($ page - 1 ) * $ perPage ;
282
- $ sliced = array_slice ($ results , $ start , $ perPage );
283
283
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
+ );
287
298
}
288
299
289
300
/**
0 commit comments