本文整理匯總了PHP中Eloquent::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Eloquent::count方法的具體用法?PHP Eloquent::count怎麽用?PHP Eloquent::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Eloquent
的用法示例。
在下文中一共展示了Eloquent::count方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: query
/**
* @param $className
* @param $parameters
* @param bool $runQuery
* @return array
*/
public function query($className, $parameters, $runQuery = true)
{
// set the default parameters
$defaultParameters = array('where' => null, 'limit' => null, 'skip' => null, 'order' => null, 'keys' => null, 'count' => null, 'include' => null);
$parameters = array_merge($defaultParameters, $parameters);
extract($parameters);
// specify the selected columns
$selected_columns = $this->select($keys);
// eager loading functionality
$this->with($include);
// filtering the data
// todo review this line
$query = $this->object instanceof Model ? $this->object->query() : $this->object;
$this->object = $this->where($query, $where);
// support pagination using limit and skip (offset)
$this->limit($limit, $skip);
// order the result
$this->order($order);
if ($runQuery) {
// prepare the json main structure
$jsonData = array('results' => array());
// run the query based on the above configuration
$jsonData['results'] = $this->object->get($selected_columns);
if (!is_null($count)) {
// add the count index if the user ask for
$jsonData['count'] = $this->object->count();
}
// return the parsed results and count if available
return $jsonData;
}
}
示例2: count
/**
* @return integer
*/
public function count()
{
return $this->model->count();
}