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


PHP Model::getForeignKey方法代码示例

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


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

示例1: aggregate

 /**
  * Aggregates data handling to the subclasses.
  *
  * @param  array       $data  the handling internediate data.
  * @param  array|Model $value the handling Model instance.
  * @return array              the resulting intermediate Format instance.
  */
 protected function aggregate(array $data, Model $value)
 {
     $data[self::KEY_OF_TABLE_NAME] = $value->getTable();
     $data[self::KEY_OF_FOREIGN_KEY] = $value->getForeignKey();
     $data[self::KEY_OF_OTHER_KEY] = $value->getOtherKey();
     return $data;
 }
开发者ID:shingoOKAWA,项目名称:yacache-l5-php,代码行数:14,代码来源:PivotFormat.php

示例2: firstOrCreateTranslation

 /**
  * Creates a translation.
  *
  * @param Model  $locale
  * @param string $text
  * @param Model  $parentTranslation
  *
  * @return Model
  */
 protected function firstOrCreateTranslation(Model $locale, $text, $parentTranslation = null)
 {
     // We'll check to see if there's a cached translation
     // first before we try and hit the database.
     $cachedTranslation = $this->getCacheTranslation($locale, $text);
     if ($cachedTranslation instanceof Model) {
         return $cachedTranslation;
     }
     // Check if auto translation is enabled. If so we'll run
     // the text through google translate and
     // save it, then cache it.
     if ($parentTranslation && $this->autoTranslateEnabled()) {
         $googleTranslate = new TranslateClient();
         $googleTranslate->setSource($parentTranslation->locale->code);
         $googleTranslate->setTarget($locale->code);
         try {
             $text = $googleTranslate->translate($text);
         } catch (ErrorException $e) {
             // Request to translate failed, set the text
             // to the parent translation
             $text = $parentTranslation->translation;
         } catch (UnexpectedValueException $e) {
             // Looks like something other than text was passed in,
             // we'll set the text to the parent translation
             // for this exception as well
             $text = $parentTranslation->translation;
         }
     }
     $translation = $this->translationModel->firstOrCreate([$locale->getForeignKey() => $locale->getKey(), $this->translationModel->getForeignKey() => isset($parentTranslation) ? $parentTranslation->getKey() : null, 'translation' => $text]);
     // Cache the translation so it's retrieved faster next time
     $this->setCacheTranslation($translation);
     return $translation;
 }
开发者ID:mohamedsharaf,项目名称:translation-1,代码行数:42,代码来源:Translation.php

示例3: getJoinClause

 /**
  * @param \Illuminate\Database\Eloquent\Model $model
  * @param string $locale
  * @param string $alias
  * @return callable
  */
 protected function getJoinClause(Eloquent $model, $locale, $alias)
 {
     return function (JoinClause $join) use($model, $locale, $alias) {
         $primary = $model->getTable() . '.' . $model->getKeyName();
         $foreign = $model->getForeignKey();
         $langKey = $model->getLocaleKey();
         $join->on($alias . '.' . $foreign, '=', $primary)->where($alias . '.' . $langKey, '=', $locale);
     };
 }
开发者ID:webfactorybulgaria,项目名称:Core,代码行数:15,代码来源:TranslatableScope.php

示例4: createWhere

 /**
  * @param \Illuminate\Database\Eloquent\Builder $builder
  * @param \Illuminate\Database\Eloquent\Model $model
  */
 protected function createWhere(EloquentBuilder $builder, Eloquent $model)
 {
     if ($model->getOnlyTranslated() && $model->shouldFallback()) {
         $key = $model->getForeignKey();
         $primary = "{$this->i18nTable}.{$key}";
         $fallback = "{$this->i18nTable}_fallback.{$key}";
         $ifNull = $builder->getQuery()->compileIfNull($primary, $fallback);
         $builder->whereRaw("{$ifNull} is not null");
     }
 }
开发者ID:laraplus,项目名称:translatable,代码行数:14,代码来源:TranslatableScope.php

示例5: buildDictionary

 /**
  * Build model dictionary keyed by the relation's foreign key.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $results
  * @return array
  */
 protected function buildDictionary(Collection $results)
 {
     $dictionary = array();
     $foreign = $this->farParent->getForeignKey();
     // First we will create a dictionary of models keyed by the foreign key of the
     // relationship as this will allow us to quickly access all of the related
     // models without having to do nested looping which will be quite slow.
     foreach ($results as $result) {
         $dictionary[$result->{$foreign}][] = $result;
     }
     return $dictionary;
 }
开发者ID:kartx22,项目名称:Otoru-Dice,代码行数:18,代码来源:HasManyThrough.php

示例6: firstOrCreateTranslation

 /**
  * Creates a translation.
  *
  * @param Model  $locale
  * @param string $text
  * @param Model  $parentTranslation
  *
  * @return Model
  */
 protected function firstOrCreateTranslation(Model $locale, $text, $parentTranslation = null)
 {
     // We'll check to see if there's a cached translation
     // first before we try and hit the database.
     $cachedTranslation = $this->getCacheTranslation($locale, $text);
     if ($cachedTranslation instanceof Model) {
         return $cachedTranslation;
     }
     // Check if auto translation is enabled. If so we'll run
     // the text through google translate and
     // save it, then cache it.
     if ($parentTranslation && $this->autoTranslateEnabled()) {
         $this->client->setSource($parentTranslation->locale->code);
         $this->client->setTarget($locale->code);
         try {
             $text = $this->client->translate($text);
         } catch (ErrorException $e) {
             // Request to translate failed, set the text
             // to the parent translation.
             $text = $parentTranslation->translation;
         } catch (UnexpectedValueException $e) {
             // Looks like something other than text was passed in,
             // we'll set the text to the parent translation
             // for this exception as well.
             $text = $parentTranslation->translation;
         }
     }
     if ($parentTranslation) {
         // If a parent translation is given we're looking for it's child translation.
         $translation = $this->translationModel->firstOrNew([$locale->getForeignKey() => $locale->getKey(), $this->translationModel->getForeignKey() => $parentTranslation->getKey()]);
     } else {
         // Otherwise we're creating the parent translation.
         $translation = $this->translationModel->firstOrNew([$locale->getForeignKey() => $locale->getKey(), 'translation' => $text]);
     }
     if (empty($translation->getAttribute('translation'))) {
         // We need to make sure we don't overwrite the translation
         // if it exists already in case it was modified.
         $translation->setAttribute('translation', $text);
     }
     if ($translation->isDirty()) {
         $translation->save();
     }
     // Cache the translation so it's retrieved faster next time
     $this->setCacheTranslation($translation);
     return $translation;
 }
开发者ID:stevebauman,项目名称:translation,代码行数:55,代码来源:Translation.php

示例7: joinIntermediate

 /**
  * Join pivot or 'through' table.
  *
  * @param  \Illuminate\Database\Eloquent\Model $parent
  * @param  \Illuminate\Database\Eloquent\Relations\Relation $relation
  * @param  string $type
  * @return void
  */
 protected function joinIntermediate(Model $parent, Relation $relation, $type)
 {
     if ($relation instanceof BelongsToMany) {
         $table = $relation->getTable();
         $fk = $relation->getForeignKey();
     } else {
         $table = $relation->getParent()->getTable();
         $fk = $table . '.' . $parent->getForeignKey();
     }
     $pk = $parent->getQualifiedKeyName();
     if (!$this->alreadyJoined($join = (new Join($type, $table))->on($fk, '=', $pk))) {
         $this->query->joins[] = $join;
     }
 }
开发者ID:boukeversteegh,项目名称:eloquence,代码行数:22,代码来源:Joiner.php

示例8: only

 /**
  * set the clauses of the sql from the ids array
  * for a where in statement
  * 
  * @param  array  $ids
  * @return null
  */
 public function only(array $ids)
 {
     $tableName = $this->model->getTable();
     $this->setJoin([$tableName, $this->table . '.' . $this->model->getForeignKey(), '=', $tableName . '.id']);
     $this->setWhereIn([$tableName . '.id', $ids]);
 }
开发者ID:hugorut,项目名称:filterable,代码行数:13,代码来源:EloquentFilterable.php


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