本文整理汇总了PHP中Illuminate\Database\Query\Builder::take方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::take方法的具体用法?PHP Builder::take怎么用?PHP Builder::take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::take方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: first
/**
* Execute the query and get the first result.
*
* @param array $columns
*
* @return mixed|static
*/
public function first($columns = ['*'])
{
$this->query->take(1);
$results = $this->get($columns);
if ($results instanceof Collection) {
return $results->first();
}
return count($results) > 0 ? reset($results) : null;
}
示例2: scopeQueryWithParams
/**
* A reusable query to pass params
*
* @param Builder $query
* @param array $queryFilter
*
* @return Builder
*/
public function scopeQueryWithParams($query, $queryFilter)
{
$limit = isset($queryFilter['limit']) ? $queryFilter['limit'] : 10;
$perPage = isset($queryFilter['perPage']);
$orderBy = isset($queryFilter['orderBy']) ? $queryFilter['orderBy'] : 'created_at';
$sortOrder = isset($queryFilter['sortOrder']) ? $queryFilter['sortOrder'] : 'desc';
$query->orderBy($orderBy, $sortOrder);
if ($perPage) {
return $query->paginate($perPage);
}
return $query->take($limit);
}
示例3: buildQuery
private function buildQuery()
{
$this->query = app(get_class($this->model));
if (!empty($this->fields)) {
$this->query = $this->query->select($this->fields);
}
if (!empty($this->relations)) {
$this->relations = array_unique($this->relations);
$this->query = $this->query->with($this->relations);
}
if (!empty($this->per_page)) {
$this->query = $this->query->take($this->per_page);
}
if (count($this->conditions)) {
foreach ($this->conditions as $condition) {
$this->query = $this->query->where($condition['column'], $condition['operator'], $condition['value'], $condition['boolean']);
}
}
}
示例4: take
/**
* Alias to set the "limit" value of the query.
*
* @param int $value
* @return \Illuminate\Database\Query\Builder|static
* @static
*/
public static function take($value)
{
return \Illuminate\Database\Query\Builder::take($value);
}
示例5: execute
public function execute(Builder $query)
{
$query->take($this->getValue());
return $query;
}
示例6: getSome
public function getSome($take, $skip = 0)
{
return $this->query->take($take)->skip($skip)->get();
}
示例7: filterBySearchTerm
/**
* Filters a relationship options query by a search term
*
* @param mixed $term
* @param \Illuminate\Database\Query\Builder $query
* @param array $selectedItems
* @param \Frozennode\Administrator\Fields\Field $fieldObject
* @param string $relatedKeyTable
*/
public function filterBySearchTerm($term, QueryBuilder &$query, Field $fieldObject, array $selectedItems, $relatedKeyTable)
{
if ($term)
{
//set up the wheres
foreach ($fieldObject->getOption('search_fields') as $search)
{
$query->where($this->db->raw($search), 'LIKE', '%'.$term.'%');
}
//exclude the currently-selected items if there are any
if (count($selectedItems))
{
$query->whereNotIn($relatedKeyTable, $selectedItems);
}
//set up the limits
$query->take($fieldObject->getOption('num_options') + count($selectedItems));
}
}