当前位置: 首页>>代码示例>>PHP>>正文


PHP Builder::take方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::take方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::take方法的具体用法?PHP Builder::take怎么用?PHP Builder::take使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Builder的用法示例。


在下文中一共展示了Builder::take方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filter

 private function filter(\Illuminate\Database\Eloquent\Builder $_db)
 {
     $_db->take($this->limit);
     if (Request::get('offset')) {
         $_db->skip(Request::get('offset'));
     }
     return $_db;
 }
开发者ID:PingadoWeb,项目名称:deliveryApi,代码行数:8,代码来源:ProductsRepository.php

示例2: paging

 /**
  * 对query进行分页操作但不最终运行
  *
  * @param Builder $query query
  * @param int     $page  page
  * @param int     $take  take
  *
  * @return Builder
  */
 public static function paging($query, $page, $take)
 {
     if ($page < 1) {
         $page = 1;
     }
     $skip = ($page - 1) * $take;
     return $query->take($take)->skip($skip);
 }
开发者ID:mingshi,项目名称:printer-api,代码行数:17,代码来源:Requests.php

示例3: scopeLoadConnection

 /**
  * Load connection w/ args.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  array  $args
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeLoadConnection($query, array $args)
 {
     $first = isset($args['first']) ? $args['first'] : 15;
     $after = $this->decodeCursor($args);
     $page = isset($args['page']) ? $args['page'] : 1;
     $currentPage = $first && $after ? floor(($first + $after) / $first) : $page;
     $skip = $first * $currentPage;
     return $query->take($first)->skip($skip);
 }
开发者ID:nuwave,项目名称:lighthouse,代码行数:16,代码来源:RelayConnection.php

示例4: __call

 /**
  * @param $method
  * @param $parameters
  * @return Collection
  * @throws \Exception
  *
  * sets cache key if derived class method call
  * derived classes methods (like 'featured') are to be used as 'getFeatured'
  */
 public function __call($method, $parameters)
 {
     $realMethod = lcfirst(substr($method, 3));
     if (!method_exists($this, $realMethod)) {
         throw new \Exception("Method does not exist - " . $method);
     }
     if ($this->cache) {
         $this->cacheKey = ($this->onlyVisible ? '-' : '+') . ($this->onlyAuthored ? '-' : '+') . $this->baseName . ".{$realMethod}[" . serialize($parameters) . "]" . "\\{" . serialize($this->filters) . "\\}" . "<" . implode(',', $this->excludes) . ">";
         if ($this->limit) {
             $this->cacheKey .= "|{$this->limit}|";
         }
         if ($this->paginate) {
             $this->cacheKey .= 'p=' . (Paginator::resolveCurrentPage() ?: 1) . "&pp=" . $this->perPage;
         }
         if ($this->closure) {
             $this->cacheKey .= "{{$this->keyFragment}}";
         }
         if ($cache = Cache::get($this->cacheKey)) {
             $this->clearFilters();
             if ($this->appendExcludes) {
                 $this->excludes = array_merge($this->excludes, $cache->lists($this->identifier)->all());
                 $this->appendExcludes = false;
             }
             return $cache === 'null' ? null : $cache;
         }
     }
     $this->model = new $this->modelClass();
     $table = $this->model->getTable();
     $this->model = $this->model->newQuery();
     $this->model->select("{$table}.*");
     $this->model = $this->model->whereNotIn($table . '.' . $this->identifier, $this->excludes);
     $this->prepare($this->model);
     $this->filter($this->model, $this->filters);
     if ($this->onlyVisible) {
         $this->filterVisible($this->model);
     }
     if ($this->onlyAuthored) {
         $this->filterAuthored($this->model);
     }
     if ($this->limit) {
         $this->model->take($this->limit);
     }
     array_unshift($parameters, $this->model);
     call_user_func_array(array($this, $realMethod), $parameters);
     if ($this->closure) {
         $closure = $this->closure;
         $closure($this->model);
     }
     $result = $this->get();
     if ($this->appendExcludes) {
         $this->excludes = array_merge($this->excludes, $result->lists($this->identifier)->all());
         $this->appendExcludes = false;
     }
     $this->clearFilters();
     return $result;
 }
开发者ID:pointer-ba,项目名称:bundle,代码行数:65,代码来源:Repository.php

示例5: filter

 private function filter(\Illuminate\Database\Eloquent\Builder $_db)
 {
     $_db->take($this->limit);
     if (Request::get('offset')) {
         $_db->skip(Request::get('offset'));
     }
     if (Request::get('q')) {
         $_db->where('description', 'like', Request::get('q') . '%');
     }
     return $_db;
 }
开发者ID:PingadoWeb,项目名称:deliveryApi,代码行数:11,代码来源:CategoriesRepository.php

示例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;
 }
开发者ID:ohiocms,项目名称:core,代码行数:21,代码来源:BaseLengthAwarePaginator.php

示例7: setClauses

 /**
  * Set clauses on the query builder
  *
  * @return $this
  */
 protected function setClauses()
 {
     foreach ($this->wheres as $where) {
         $this->query->where($where['column'], $where['operator'], $where['value']);
     }
     foreach ($this->whereIns as $whereIn) {
         $this->query->whereIn($whereIn['column'], $whereIn['values']);
     }
     if (isset($this->take) and !is_null($this->take)) {
         $this->query->take($this->take);
     }
     return $this;
 }
开发者ID:edouardkombo,项目名称:spinv,代码行数:18,代码来源:BaseRepository.php

示例8: 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']);
         }
     }
 }
开发者ID:bhutanio,项目名称:laravel-utilities,代码行数:19,代码来源:DbRepository.php

示例9: setClauses

 /**
  * Set clauses on the query builder
  *
  * @return $this
  */
 protected function setClauses()
 {
     foreach ($this->wheres as $where) {
         $this->query->where($where['column'], $where['operator'], $where['value']);
     }
     foreach ($this->whereIns as $whereIn) {
         $this->query->whereIn($whereIn['column'], $whereIn['values']);
     }
     foreach ($this->orderBys as $orders) {
         $this->query->orderBy($orders['column'], $orders['direction']);
     }
     if (isset($this->take) and !is_null($this->take)) {
         $this->query->take($this->take);
     }
     if (isset($this->skip) and !is_null($this->skip)) {
         $this->query->skip($this->skip);
     }
     if (isset($this->paginate) and !is_null($this->paginate)) {
         $this->query->paginate($this->paginate);
     }
     return $this;
 }
开发者ID:Okipa,项目名称:una.app,代码行数:27,代码来源:BaseRepository.php

示例10: filterBySearchTerm

 /**
  * Filters a relationship options query by a search term
  *
  * @param mixed										$term
  * @param \Illuminate\Database\Query\Builder		$query
  * @param \Frozennode\Administrator\Fields\Field	$fieldObject
  * @param array										$selectedItems
  * @param string									$relatedKeyTable
  */
 public function filterBySearchTerm($term, EloquentBuilder &$query, Field $fieldObject, array $selectedItems, $relatedKeyTable)
 {
     if ($term) {
         $query->where(function ($query) use($term, $fieldObject) {
             foreach ($fieldObject->getOption('search_fields') as $search) {
                 $query->orWhere($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));
     }
 }
开发者ID:dmitriyuch,项目名称:Laravel-Administrator,代码行数:25,代码来源:Factory.php

示例11: scopeLimit

 /**
  * Limit the number of results
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  int                                   $limit
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeLimit(Builder $query, $limit)
 {
     return $query->take($limit);
 }
开发者ID:khaliqgant,项目名称:Deep,代码行数:11,代码来源:Category.php

示例12: queryLimitOffset

 /**
  * Query limit and offset.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  int|null                              $limit
  * @param  int                                   $offset
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function queryLimitOffset($query, $limit = null, $offset = 0)
 {
     $limit = $limit ?: $this->limit;
     $offset = $offset ?: $this->offset;
     if ($limit) {
         $query->take($limit)->skip($offset);
     }
     return $query;
 }
开发者ID:sedp-mis,项目名称:base-repository,代码行数:17,代码来源:BaseRepositoryEloquent.php

示例13: filter

 private function filter(Builder $builder, $filters)
 {
     if (isset($filters['take'])) {
         $builder->take($filters['take']);
     }
     if (isset($filters['category'])) {
         $builder->where('category_id', Category::where('slug', $filters['category'])->firstOrfail()->id);
     }
     if (isset($filters['online']) && $filters['online'] == true) {
         $builder->online();
     }
     if (isset($filters['order'])) {
         $builder->orderBy($filters['order'], 'desc');
     } else {
         $builder->latest('published_at');
     }
     return $builder;
 }
开发者ID:Amiral-TA,项目名称:LaravelTests,代码行数:18,代码来源:ArticleManager.php

示例14: page

 /**
  * Will get entries from a specified page
  *
  * @param  integer  $page
  * @param  integer  $perPage
  * @return $this
  */
 public function page($page, $perPage = 15)
 {
     $offset = $page * $perPage - $perPage;
     $this->builder = $this->builder->take($perPage)->skip($offset);
     return $this;
 }
开发者ID:kodebyraaet,项目名称:pattern,代码行数:13,代码来源:BaseRepository.php


注:本文中的Illuminate\Database\Eloquent\Builder::take方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。