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


PHP Model::newCollection方法代码示例

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


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

示例1: newCollection

 /**
  * Use the custom collection that allows tapping.
  *
  * @param array $models An array of models to turn into a collection.
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function newCollection(array $models = [])
 {
     if ($this->nukaCollections) {
         return new Collection($models);
     }
     return parent::newCollection($models);
 }
开发者ID:nukacode,项目名称:core,代码行数:14,代码来源:BaseModel.php

示例2: findMany

 /**
  * Find multiple models by their primary keys.
  *
  * @param  array  $ids
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function findMany($ids, $columns = ['*'])
 {
     if (empty($ids)) {
         return $this->model->newCollection();
     }
     $this->query->whereIn($this->model->getQualifiedKeyName(), $ids);
     return $this->get($columns);
 }
开发者ID:levanigongadze,项目名称:Labweb,代码行数:15,代码来源:Builder.php

示例3: descendantsOf

 /**
  * Get descendants of specified node.
  *
  * @since 2.0
  *
  * @param mixed $id
  * @param array $columns
  *
  * @return \Kalnoy\Nestedset\Collection
  */
 public function descendantsOf($id, array $columns = array('*'))
 {
     try {
         return $this->whereDescendantOf($id)->get($columns);
     } catch (ModelNotFoundException $e) {
         return $this->model->newCollection();
     }
 }
开发者ID:nutsdo,项目名称:nong-store,代码行数:18,代码来源:QueryBuilder.php

示例4: paginate

 /**
  * Paginate the given query.
  *
  * @param  int  $perPage
  * @param  array  $columns
  * @param  string  $pageName
  * @param  int|null  $page
  * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  *
  * @throws \InvalidArgumentException
  */
 public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
 {
     $page = $page ?: Paginator::resolveCurrentPage($pageName);
     $perPage = $perPage ?: $this->model->getPerPage();
     $query = $this->toBase();
     $total = $query->getCountForPagination();
     $results = $total ? $this->forPage($page, $perPage)->get($columns) : $this->model->newCollection();
     return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
开发者ID:illuminate,项目名称:database,代码行数:20,代码来源:Builder.php

示例5: get

 /**
  * Execute the query as a "select" statement.
  *
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public function get($columns = array('*'))
 {
     $models = $this->getModels($columns);
     // If we actually found models we will also eager load any relationships that
     // have been specified as needing to be eager loaded, which will solve the
     // n+1 query issue for the developers to avoid running a lot of queries.
     if (count($models) > 0) {
         $models = $this->eagerLoadRelations($models);
     }
     return $this->model->newCollection($models);
 }
开发者ID:aysenli,项目名称:laravel-admin-1,代码行数:17,代码来源:Builder.php

示例6: delete

 /**
  * Delete a model by the following:
  *     $model               itself when a model is given
  *     [$model[,...]]       array or collection of models
  *     $id                  id of the model
  *     [id1[, id2, ...]]    array of ids.
  *
  * @param  mixed    $model
  * @return bool|int Boolean when model is deleted or the number of models deleted
  */
 public function delete($model)
 {
     // First use-case, itself when a model is given
     if ($model instanceof $this->model) {
         return $model->delete();
     }
     // Second use-case, array or collection of models
     $models = $model;
     if (is_array($models) && head($models) instanceof $this->model) {
         $models = $this->model->newCollection($models);
     }
     if ($models instanceof Collection) {
         $model = $models->pluck('id');
         // Pass ids to $model to be deleted below on third and fourth use-case
     }
     // Third and fourth use-case, id or array of ids
     $ids = $model;
     if (is_int($model)) {
         $ids = [$ids];
     }
     if (!empty($ids)) {
         return $this->model->destroy($ids);
     }
 }
开发者ID:sedp-mis,项目名称:base-repository,代码行数:34,代码来源:BaseRepositoryEloquent.php


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