/**
  * Paginate the returned set of models.
  *
  * @param  int      $perPage
  * @param  array    $columns
  * @param  string   $pageName
  * @param  int|null $page
  * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  *
  * @throws \InvalidArgumentException
  */
 public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
 {
     $query = $this->model->toBase();
     $total = $query->getCountForPagination();
     $model = $this->model->forPage($page = $page ?: Paginator::resolveCurrentPage($pageName), $perPage = $perPage ?: $this->model->getPerPage());
     $results = new LengthAwarePaginator($this->hookPaginate($model->get($columns)), $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
     $this->reset();
     return $results;
 }