当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::getRelations方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::getRelations方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getRelations方法的具体用法?PHP Model::getRelations怎么用?PHP Model::getRelations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::getRelations方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveRelations

 private function saveRelations()
 {
     /** @var Eloquent $related */
     foreach ($this->original->getRelations() as $related) {
         if ($related->isDirty()) {
             if ($related->save() === false) {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:wutongwan,项目名称:laravel-lego,代码行数:12,代码来源:EloquentRow.php

示例2: toArray

 /**
  * Get the instance as an array.
  *
  * @return array
  */
 public function toArray()
 {
     $model = [];
     foreach ($this->model->attributesToArray() as $attribute => $value) {
         $model[$attribute] = $this->{$attribute};
         if (is_object($model[$attribute]) && is_callable([$model[$attribute], 'toArray'])) {
             $model[$attribute] = $model[$attribute]->toArray();
         }
     }
     foreach ($this->model->getRelations() as $relationName => $relation) {
         try {
             $pivotRelationName = $relation->relationName;
         } catch (Exception $e) {
             // Fall though...
         }
         if (isset($pivotRelationName)) {
             $relationName = $pivotRelationName;
         }
         if (is_object($relation) && is_callable([$relation, 'toArray'])) {
             $model[$relationName] = $relation->toArray();
         } else {
             $model[$relationName] = $relation;
         }
     }
     if (!empty($this->additionalAttributes)) {
         foreach ($this->additionalAttributes as $attribute) {
             $model[$attribute] = $this->{$attribute};
             if (is_object($model[$attribute]) && is_callable([$model[$attribute], 'toArray'])) {
                 $model[$attribute] = $model[$attribute]->toArray();
             }
         }
     }
     return $model;
 }
开发者ID:artissant,项目名称:laravel,代码行数:39,代码来源:ViewModel.php

示例3: castModel

 /**
  * Get an array representing the properties of a model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return array
  */
 public static function castModel(Model $model)
 {
     $attributes = array_merge($model->getAttributes(), $model->getRelations());
     $visible = array_flip($model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden()));
     $results = [];
     foreach (array_intersect_key($attributes, $visible) as $key => $value) {
         $results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL : Caster::PREFIX_PROTECTED) . $key] = $value;
     }
     return $results;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:16,代码来源:IlluminateCaster.php

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

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

示例6: linksToEntityRelations

 /**
  * Creates Links to all of the provided Model's relations
  *
  * Keep in mind that relations may only be scanned after they are attached to a certain Model, which means "join"
  * operation(s) where triggered. For example: with() method was called on the Model with params!
  *
  * @param Model $ent                    The Model that provides the Relations for our links
  * @param bool $forceReturn             If set to true, it will return an empty array, and won't throw an Exception
  * @throws \InvalidArgumentException
  * @return array
  */
 public function linksToEntityRelations(Model $ent, $forceReturn = false)
 {
     $links = [];
     $relations = $ent->getRelations();
     if (!is_array($relations) || count($relations) == 0) {
         if ($forceReturn === false) {
             throw new \InvalidArgumentException('Provided Entity does not contain any relations, can\'t generate links...');
         }
         return $links;
     }
     foreach ($relations as $key => $rel) {
         if ($rel instanceof ResourceEntity) {
             $links[] = $this->createLink($rel->getRootRelName(), $this->request->url() . '/' . $rel->getRootRelName());
         } else {
             $links[] = $this->createLink($key, $this->request->url() . '/' . $key);
         }
     }
     return $links;
 }
开发者ID:noherczeg,项目名称:restext,代码行数:30,代码来源:RestLinker.php

示例7: resolveRelations

 /**
  * Resolve eager loaded relations from the model.
  *
  * @param  \Illuminate\Database\Eloquent\Model $model
  * @return array
  */
 protected function resolveRelations(Model $model) : array
 {
     return array_keys($model->getRelations());
 }
开发者ID:flugger,项目名称:laravel-responder,代码行数:10,代码来源:SuccessResponseBuilder.php


注:本文中的Illuminate\Database\Eloquent\Model::getRelations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。