當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。