Run a pagination count query.

@param  array  $columns
@return array
327706
protected function runPaginationCountQuery($columns = ['*'])
    {
        $bindings = $this->from instanceof Subquery ? ['order'] : ['select', 'order'];

        return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
                    ->cloneWithoutBindings($bindings)
                    ->setAggregate('count', $this->withoutSelectAliases($columns))
                    ->get()->all();
    }
836783
public function getFresh($columns = array('*'))
	{
		if (is_null($this->columns)) $this->columns = $columns;

        return $this->runSelect();
	}
51482
public function get($columns = ['*'])
    {
        // First we'll add the proper select columns onto the query so it is run with
        // the proper columns. Then, we will get the results and hydrate out pivot
        // models with the result of those columns as a separate model relation.
        $columns = $this->query->getQuery()->columns ? [] : $columns;

        $builder = $this->query->applyScopes();

        $models = $builder->addSelect(
            $this->shouldSelect($columns)
        )->getModels();

        $this->hydratePivotRelation($models);

        // If we actually found models we will also eager load any relationships that
        // have been specified as needing to be eager loaded. This will solve the
        // n + 1 query problem for the developer and also increase performance.
        if (count($models) > 0) {
            $models = $builder->eagerLoadRelations($models);
        }

        return $this->related->newCollection($models);
    }
255753
public function first($columns = ['*'])
    {
        $result = $this->getBuilder()->first($columns);

        // Reset query builder
        $this->resetBuilder();

        return $result;
    }
309224
public function Columns($columns = ''): QueryBuilder
    {
        if (empty($columns)) {
            return $this;
        }
        
        if (! is_array($columns)) {
            $this->fields = explode(',', $columns);
        }
        
        $this->fields = array_map('trim', $this->fields);
        
        return $this;
    }
922331
public function paginate(int $perPage = 15, array $columns = ['*'], $pageName = 'page', int $page = 0): LengthAwarePaginator
    {
        $paginate = $this->queryRelate->getQuery()->paginate($perPage, $columns, $pageName, $page);

        $this->resetQueryRelate();

        return $paginate;
    }
47788
public function paginate($perPage = null, $columns = array('*'))
	{
		$this->query->addSelect($this->getSelectColumns($columns));

		$paginator = $this->query->paginate($perPage, $columns);

		$this->hydratePivotRelation($paginator->items());

		return $paginator;
	}
809567
public function getCountForPagination($columns = ['*'])
    {
        $this->backupFieldsForCount();

        $this->aggregate = ['function' => 'count', 'columns' => $columns];


        $results = $this->get();

        $this->aggregate = null;

        $this->restoreFieldsForCount();

        if (isset($this->groups)) {
            return count($results);
        }

        $row = null;
        if ($results->offsetExists(0)) {
                $row = $results->offsetGet(0);
                $count = $row->offsetGet(0);
                return $count;
        } else {
                return 0;
        }
    }
714455
public function getLastChild(array $columns = ['*'])
    {
        if ($this->hasChildrenRelation()) {
            $result = $this->getRelation($this->getChildrenRelationIndex())->last();
        } else {
            $result = $this->children(static::QUERY_LAST)->first($columns);
        }

        return $result;
    }
880473
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
    {
        $per_page = ($this->request->has('per_page'))
            ? $this->request->get('per_page')
            : $perPage;

        $paginator = $this->db->paginate($per_page, $columns, $pageName, $page);

        $paginator->appends($this->request->all());

        return $paginator;
    }
505489
public function first($columns = array('*'))
    {
        $results = $this->take(1)->get($columns)->current();

        return (isset($results[0]) && count($results[0]) > 0) ? $results[0]->getProperties() : null;
    }
1264090
public function paginate($limit = null, $columns = ['*'], $pageName = 'page', $page = null)
    {
        return $this->simpleWrap(Action::READ, [$this, '_paginate']);
    }
471921
public function paginate($perPage = null, $columns = array('*'), $pageName = 'page', $page = null)
    {
        if (is_null($page)) {
            $page = Paginator::resolveCurrentPage($pageName);
        }

        $path = Paginator::resolveCurrentPath($pageName);

        if (is_null($perPage)) {
            $perPage = $this->model->getPerPage();
        }

        $total = $this->query->getPaginationCount();

        if ($total > 0) {
            $results = $this->forPage($page, $perPage)->get($columns);
        } else {
            $results = $this->model->newCollection();
        }

        return new Paginator($results, $total, $perPage, $page, compact('path', 'pageName'));
    }
136357
public function paginate($limit = null, $columns = ['*'], $method = 'paginate')
    {
        if (!$this->allowedCache('paginate') || $this->isSkippedCache()) {
            return parent::paginate($limit, $columns, $method);
        }

        $key = $this->getCacheKey('paginate', func_get_args());

        $minutes = $this->getCacheMinutes();
        $value = $this->getCacheRepository()->remember($key, $minutes, function () use ($limit, $columns, $method) {
            return parent::paginate($limit, $columns, $method);
        });

        $this->resetModel();
        $this->resetScope();
        return $value;
    }
264890
private function getCount($column)
    {
        $alias = 'count';

        // Save initial state
        $original = clone $this->queryBuilder;
        $bindings = $this->bindings;

        // Set guessed query and execute it
        $this->queryBuilder->setQueryString($this->queryBuilder->guessCountQuery($column, $alias));
        $count = $this->query($alias);

        // And finally restore initial state
        $this->queryBuilder = $original;
        $this->bindings = $bindings;

        return $count;
    }
984297
public function firstOrFail($columns = ['*'])
    {
        if (! is_null($model = $this->first($columns))) {
            return $model;
        }
        throw new RuntimeException("No query results for model [".get_class($this->model)."]");
    }
973364
public function get($columns = array('*'))
	{
		if (!$this->applyMetaFilters()) {
			if (!empty($this->aggregate)) {
				return 0;
			}
			return $this->model->newCollection();
		}
		
		if (!empty($this->aggregate)) {
			return parent::get($columns);
		}
		else {
			$results = parent::get(array('m.xref_id'));
		}
		
		if (empty($results)) {
			return $this->model->newCollection();
		}
		
		$xref_ids = array();
		foreach ($results as $result) {
			if (!isset($result->xref_id)) continue;
			$xref_ids[] = $result->xref_id;
		}
		
		if (empty($xref_ids)) {
			return $this->model->newCollection();
		}
		
		$key = $this->model->getKeyName();
		
		$models = $this->model->newQuery()->whereIn($key, $xref_ids)->get();
		
		$models->sortBy(function ($model) use ($xref_ids, $key) {
			foreach ($xref_ids as $idx => $i) {
				if ($model->{$key} == $i) {
					return $idx;
				}
			}
			return 0;
		});
		
		if (!empty($this->relations)) {
			$models->load($this->relations);
		}
		
		return $models;
	}