@@ -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