本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::count方法的具体用法?PHP Builder::count怎么用?PHP Builder::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::count方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: totalCount
public function totalCount()
{
if ($this->options['distinctCountGroup'] && count($this->originalBuilder->groups) == 1) {
$this->originalBuilder->groups = null;
}
if ($this->options['searchWithAlias']) {
$cnt = count($this->originalBuilder->get());
} else {
$cnt = $this->originalBuilder->count();
}
return $cnt;
}
示例2: canFind
/**
* @param array $attributes
* @return bool
* @throws BadDataQueryException
*/
public function canFind(array $attributes)
{
foreach ($attributes as $key => $value) {
$this->where($key, $value);
}
return $this->model->count() > 0;
}
示例3: count
/**
* Count rows
*
* @return Integer
*/
public function count()
{
// Save the results from the builder
$result = $this->builder->count();
// Reset the builder, just in case we are going to use this repository more then once
$this->newBuilder();
return $result;
}
示例4: scopeRandom
/**
* Scope a query to only one random item.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRandom($query)
{
$total = $query->count();
if ($total > 1) {
$offset = mt_rand(0, $total - 1);
$query = $query->skip($offset)->take(1);
}
return $query;
}
示例5: getItems
public function getItems($limit, $offset)
{
$builder = $this->query->getQuery();
if ($builder->groups || $builder->unions) {
$row = DB::selectOne("SELECT COUNT(*) qty FROM (" . $this->query->toSql() . ") sub", $this->query->getBindings());
$total = (int) $row->qty;
} else {
$total = $this->query->count();
}
$pageOfItems = $this->query->skip($offset)->take($limit)->get();
return [$pageOfItems, $total];
}
示例6: build
public function build()
{
$request = $this->request;
$needle = $request->needle();
if ($needle && $request->searchable) {
$this->qb->where(function ($subQB) use($needle, $request) {
foreach ($request->searchable as $column) {
$subQB->orWhere($column, 'LIKE', "%{$needle}%");
}
});
}
$request->modifyQuery($this->qb);
$this->qb->orderBy($request->orderBy(), $request->sortBy());
$count = $this->qb->count();
$this->qb->take($request->perPage());
$this->qb->offset($request->offset());
$paginator = new LengthAwarePaginator($request->items($this->qb), $count, $request->perPage(), $request->page());
$paginator->request = $request;
$paginator->appends($request->query());
$this->paginator = $paginator;
}
示例7: pagination
/**
* Возвращает коллекцию в виде пагинации
*
* @param int $page
* @param int $limit
*/
public function pagination($page, $limit = 10)
{
/**
* @var \Illuminate\Support\Collection $data
*/
$countTotal = $this->_query->count();
$this->_query->skip($limit * $page - $limit);
$this->_query->limit($limit);
$data = collect();
foreach ($this->_query->get() as $key => $instance) {
$_listRow = [];
foreach ($this->columns->getColumns() as $column) {
$_listRow[$column->getKey()] = $column->getValues($instance);
}
$buttons = $this->filterAction($instance);
if (count($buttons)) {
$_listRow = array_merge($_listRow, [GridColumn::ACTION_NAME => implode('', $buttons)]);
}
$data->offsetSet($key, $_listRow);
}
return new \Illuminate\Pagination\LengthAwarePaginator($data, $countTotal, $limit, $page, ['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath(), 'pageName' => 'page']);
}
示例8: count
/**
* @return int
*/
public function count()
{
return $this->specificationQuery->count();
}
示例9: totalCount
public function totalCount()
{
return $this->originalBuilder->count();
}
示例10: count
/**
* Get the entry count.
*
* @param array $columns
* @return int
*/
public function count(array $columns = ['*'])
{
return (new Decorator())->decorate($this->query->count($columns));
}
示例11: getItems
public function getItems($requestedLimit, $requestedOffset)
{
$items = $this->collection->slice($requestedOffset, $requestedLimit);
return [$items, $this->collection->count()];
}
示例12: count
/**
* @return int
*/
public function count()
{
return $this->builder->count();
}
示例13: format
/**
* Formatting the returned data in an associative array representation of the required datatables response object.
* @param Builder $originalQuery Original Eloquent query object before applying datatables process, use alt query if aggregate functions are used with the original.
* @param array $data Returned data collection after processing.
* @return array Associative array (object) that is required for responding to datatables request.
*/
public static function format(Builder $originalQuery, $data)
{
$recordsTotal = is_null(self::$distinctField) ? $originalQuery->count() : $originalQuery->select(DB::raw('COUNT(DISTINCT ' . self::$distinctField . ') AS total'))->get()->toArray()[0]['total'];
return ['draw' => Request::input('draw'), 'recordsFiltered' => self::$totalFiltered, 'data' => $data] + compact('recordsTotal');
}