當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。