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


PHP Builder::getEagerLoads方法代碼示例

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


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

示例1: eagerLoadRelations

 /**
  * Eager load relationships on collection.
  *
  * @param  Builder $builder
  * @param  array   $models
  * @return array
  */
 public function eagerLoadRelations(Builder $builder, array $models)
 {
     foreach ($builder->getEagerLoads() as $name => $constraints) {
         if (strpos($name, '.') === false) {
             $models = $this->loadRelation($builder, $models, $name, $constraints);
         }
     }
     return $models;
 }
開發者ID:nuwave,項目名稱:lighthouse,代碼行數:16,代碼來源:QueryBuilder.php

示例2: apply

 /**
  * @param Builder  $builder
  * @param Eloquent $model
  *
  * @throws \InvalidArgumentException
  */
 public function apply(Builder $builder, Eloquent $model)
 {
     $query = $builder->getQuery();
     if (count($loads = $builder->getEagerLoads()) === 0 && count($query->wheres) === 0 || count($properties = Factory::getPropertiesByEntity($model)) === 0) {
         return;
     }
     //compact eager loading
     if (count($loads) > 0) {
         $eadgeLoads = [];
         $props = [];
         foreach ($loads as $load => $data) {
             if ($properties->has($load)) {
                 $props[$load] = $properties->get($load);
                 //$eadgeLoads[$load] = $data;
             } else {
                 $eadgeLoads[$load] = $data;
             }
         }
         if (count($props)) {
             $eadgeLoads = ['values' => function (Values $relation) use($props) {
                 $relation->setProperties(new Collection($props));
             }] + $eadgeLoads;
         }
         $builder->setEagerLoads($eadgeLoads);
     }
     $table = $model->getTable();
     $columns = $this->parseWhere($properties, $query->wheres, $table);
     if (count($columns) === 0) {
         return;
     }
     $value = new Value();
     $query->select($table . '.*');
     $multiple = false;
     foreach ($columns as $alias => $property) {
         if ($property->multiple) {
             $multiple = true;
         }
         $query->leftJoin($value->getTable() . ' AS ' . $alias, function (JoinClause $join) use($model, $alias, $property) {
             $join->on($model->getTable() . '.' . $model->getKeyName(), '=', $alias . '.entity_id');
             $join->where($alias . '.property_id', '=', $property->id);
         });
     }
     if ($multiple) {
         //Distinct if condition by multiple values
         $query->distinct();
     }
 }
開發者ID:dkulyk,項目名稱:eloquent-extra,代碼行數:53,代碼來源:QueryScope.php

示例3: parseWith

 /**
  * Parse the with parameter.
  *
  * @param  string $params
  * @return void
  */
 protected function parseWith($params)
 {
     $with = explode(',', $params);
     $with = in_array('*', $this->withable) ? $with : array_only($with, $this->withable);
     foreach ($this->additionalSorts as $sort => $direction) {
         $parts = explode('.', $sort);
         $realKey = array_pop($parts);
         $relation = implode('.', $parts);
         if (in_array($relation, $with)) {
             $this->builder->with([$relation => function ($query) use($realKey, $direction) {
                 $query->orderBy($realKey, $direction);
             }]);
             if (($key = array_search($relation, $with)) !== false) {
                 unset($with[$key]);
             }
         }
     }
     if (!empty($with)) {
         $this->builder->with($with);
     }
     $this->with = $this->builder->getEagerLoads();
 }
開發者ID:jenky,項目名稱:laravel-api-helper,代碼行數:28,代碼來源:Handler.php

示例4: getEagerLoads

 /**
  * Get the relationships being eagerly loaded.
  *
  * @return array 
  * @static 
  */
 public static function getEagerLoads()
 {
     return \Illuminate\Database\Eloquent\Builder::getEagerLoads();
 }
開發者ID:satriashp,項目名稱:tour,代碼行數:10,代碼來源:_ide_helper.php

示例5: hasEagerLoad

 /**
  * @return bool
  */
 protected function hasEagerLoad()
 {
     return $hasEagerLoad = (bool) count($this->builder->getEagerLoads());
 }
開發者ID:johnrich85,項目名稱:eloquent-query-modifier,代碼行數:7,代碼來源:BaseModifier.php


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