/** * Paginate query results * @param Builder $query * @param integer $perPage * @return array */ public function paginate($perPage = null) { $collectionClass = $this->collectionClass; $perPage = $this->limit(); $this->paginated = $this->query->paginate($perPage); $pagination = $this->paginated->toArray(); $this->collection = new $collectionClass(array_get($pagination, 'data')); return $this->collection; }