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