當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Model::with方法代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Model::with方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::with方法的具體用法?PHP Model::with怎麽用?PHP Model::with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::with方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getRoleByName

 public function getRoleByName($roleName)
 {
     $query = $this->model->with('roles')->whereHas('roles', function ($q) use($roleName) {
         $q->where('name', '=', $roleName);
     })->get();
     return $query;
 }
開發者ID:christiannwamba,項目名稱:laravel-site,代碼行數:7,代碼來源:UserRepository.php

示例2: with

 public function with($relations)
 {
     if (is_string($relations)) {
         $relations = func_get_args();
     }
     $this->model = $this->model->with($relations);
     return $this;
 }
開發者ID:vnzacky,項目名稱:dog,代碼行數:8,代碼來源:EloquentBaseRepository.php

示例3: eagerLoading

 /**
  * @return $this
  */
 protected function eagerLoading()
 {
     if (!is_null($this->relations)) {
         $this->model = $this->model->with($this->relations);
     }
     return $this;
 }
開發者ID:Ontoo-Inc,項目名稱:Repository,代碼行數:10,代碼來源:BaseRepository.php

示例4: getCollectionByColumn

 /**
  * Get instance of model by column
  *
  * @param  mixed $term search term
  * @param  string $column column to search
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function getCollectionByColumn($term, $column = 'slug')
 {
     $query = function () use($term, $column) {
         return $this->model->with($this->requiredRelationships)->where($column, '=', $term)->get();
     };
     return $this->doQuery($query);
 }
開發者ID:dannyweeks,項目名稱:laravel-base-repository,代碼行數:14,代碼來源:BaseEloquentRepository.php

示例5: with

 /**
  * Load relations
  *
  * @param array|string $relations
  * @return $this
  */
 public function with($relations)
 {
     /**
      * Save to conditons.
      */
     $this->addCondition('with', $relations);
     $this->model = $this->model->with($relations);
     return $this;
 }
開發者ID:sandeeprajoria,項目名稱:Housekeeper,代碼行數:15,代碼來源:BaseRepository.php

示例6: index

 /**
  * Display a paginated list of the resource.
  *
  * @param  Paginator
  * @return Response
  */
 public function index($resources = null)
 {
     // Get the resources if they have not been provided by the child class
     if (is_null($resources)) {
         $resources = $this->resource->with($this->with)->paginate();
     }
     // Load view
     return view('resource.index', ['title' => $this->title ?: $this->resource->plural, 'subtitle' => $this->subtitle ?: _('Index'), 'resources' => $resources]);
 }
開發者ID:LeandrosilvaDG,項目名稱:Wiki,代碼行數:15,代碼來源:ResourceController.php

示例7: 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

示例8: findByIdWithRelation

 /**
  * Find instance with relation by id.
  *
  * @param  integer $id
  * @param  string|array $relations
  *
  * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
  */
 public function findByIdWithRelation($id, $relations)
 {
     return $this->model->with($relations)->findOrFail($id);
 }
開發者ID:RryLee,項目名稱:learner.video,代碼行數:12,代碼來源:AbstractRepository.php

示例9: make

 /**
  * returns the query builder with eager loading, or the model itself
  *
  * @return Builder|Model
  */
 protected function make()
 {
     return $this->model->with($this->with);
 }
開發者ID:ipunkt,項目名稱:laravel-repositories,代碼行數:9,代碼來源:EloquentRepository.php

示例10: with

 /**
  * Load relations.
  *
  * @param array|string $relations
  *
  * @return $this
  */
 public function with($relations)
 {
     $this->model = $this->model->with($relations);
     return $this;
 }
開發者ID:LavaliteCms,項目名稱:Example,代碼行數:12,代碼來源:BaseRepository.php

示例11: page

 /**
  * Returns a range of records bounded by pagination parameters.
  *
  * @param int limit
  * @param int $offset
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function page($limit = 10, $offset = 0, array $relations = [], $orderBy = 'updated_at', $sorting = 'desc')
 {
     return $this->model->with($relations)->take($limit)->skip($offset)->orderBy($orderBy, $sorting)->get();
 }
開發者ID:vinelab,項目名稱:lucid,代碼行數:12,代碼來源:Repository.php

示例12: getModelWith

 /**
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function getModelWith()
 {
     return $this->model->with($this->with);
 }
開發者ID:catchup-forks,項目名稱:startersite,代碼行數:7,代碼來源:Repository.php

示例13: with

 /**
  * Load relations.
  *
  * @param string|array $relation
  *
  * @return this
  */
 public function with($relations)
 {
     $relations = is_array($relations) ? $relations : func_get_args();
     $this->model = $this->model->with($relations);
     return $this;
 }
開發者ID:sjfinder,項目名稱:repository,代碼行數:13,代碼來源:BaseRepository.php

示例14: find

 /**
  * @param $id
  * @param array|null $with
  * @return mixed
  */
 public function find($id, $with = [])
 {
     return $this->model->with($with)->findOrFail($id);
 }
開發者ID:team-ccsad,項目名稱:project-101,代碼行數:9,代碼來源:EloquentRepository.php

示例15: applyRelations

 /**
  * Apply any relationships to eager-load.
  *
  * @param Builder|Model $query
  * @return Builder|Model
  */
 protected function applyRelations($query)
 {
     if (!empty($this->relations)) {
         return $query->with($this->relations);
     }
     return $query;
 }
開發者ID:artissant,項目名稱:stock,代碼行數:13,代碼來源:Repository.php


注:本文中的Illuminate\Database\Eloquent\Model::with方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。