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


PHP Model::setRelation方法代碼示例

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


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

示例1: decorateRelations

 /**
  * Decorate the relationships of an Eloquent object.
  *
  * @param \Illuminate\Database\Eloquent\Model $atom
  *
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function decorateRelations(Model $atom)
 {
     foreach ($atom->getRelations() as $relationName => $model) {
         if ($model instanceof Collection) {
             $model = $this->createDecorator('Collection')->decorate($model);
             $atom->setRelation($relationName, $model);
         } else {
             $atom->setRelation($relationName, $this->decorate($model));
         }
     }
     return $atom;
 }
開發者ID:ssomenzi,項目名稱:silence,代碼行數:19,代碼來源:AtomDecorator.php

示例2: buildRelations

 /**
  * Build the view model representations of the relations.
  *
  * @return void
  */
 protected function buildRelations()
 {
     $relations = $this->model->getRelations();
     foreach ($relations as $relationName => $relation) {
         // TODO: handle MorphToMany
         //if ($relation instanceof MorphPivot) {
         //    dd($relation->getMorphClass(), $relation);
         //    dd(get_class_methods($relation));
         //}
         // For pivots, we'll test for the snake cased version of the class name as the
         // relation's name, and check if a view model class has been defined on this
         // view model's relations.
         if ($relation instanceof Pivot) {
             $originalRelationName = $relationName;
             $relationName = $this->relationName ?: snake_case(class_basename($relation));
             if (isset($this->relations[$relationName])) {
                 $relationViewModel = $this->relations[$relationName];
                 $relation = static::make($relation, $relationViewModel);
                 $this->model->setRelation($originalRelationName, $relation);
             }
         } elseif (isset($this->relations[$relationName])) {
             $relationViewModel = $this->relations[$relationName];
             $relation = static::make($relation, $relationViewModel);
             $this->model->setRelation($relationName, $relation);
         }
     }
 }
開發者ID:artissant,項目名稱:laravel,代碼行數:32,代碼來源:ViewModel.php

示例3: loadPivotAttribute

 /**
  * Get the pivot attribute from a model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  \Illuminate\Database\Eloquent\Relations\Relation  $parentRelation
  */
 public static function loadPivotAttribute(Model $model, Relation $parentRelation = null)
 {
     $attributes = $model->getAttributes();
     foreach ($attributes as $key => $value) {
         if ($key === 'pivot') {
             unset($model[$key]);
             $pivot = $parentRelation->newExistingPivot($value);
             $model->setRelation($key, $pivot);
         }
     }
 }
開發者ID:damnyan,項目名稱:elasticquent,代碼行數:17,代碼來源:ElasticquentTrait.php

示例4: decorateModelRelations

 /**
  * Decorate an Eloquent models relations.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @return void
  */
 protected function decorateModelRelations(Model $model)
 {
     if ($relations = $model->getRelations()) {
         foreach ($relations as $key => $value) {
             $model->setRelation($key, $this->decorate($value));
         }
     }
 }
開發者ID:ungly,項目名稱:book,代碼行數:15,代碼來源:Decorator.php

示例5: setRelation

 /**
  * Set the specific relationship in the model.
  *
  * @param  string $relationName
  * @param  mixed $value
  * @param Relation|null $relation
  * @return $this
  */
 public function setRelation($relationName, $value, $relation = null)
 {
     if ($relation instanceof Relation) {
         static::$relationsCache[$this->getRelationCacheKey($relationName)] = $relation;
     }
     return parent::setRelation($relationName, $value);
 }
開發者ID:TFidryForks,項目名稱:spira,代碼行數:15,代碼來源:BaseModel.php

示例6: updateValue

 /**
  * Set value to relation.
  *
  * @param string $key
  */
 public function updateValue($key)
 {
     $this->entity->setRelation($key, $this->getValue($key));
 }
開發者ID:dkulyk,項目名稱:eloquent-extra,代碼行數:9,代碼來源:Factory.php


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