当前位置: 首页>>代码示例>>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;未经允许,请勿转载。