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


PHP Model::belongsTo方法代码示例

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


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

示例1: belongsTo

 public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
 {
     return parent::belongsTo($related, $foreignKey, $this->isOracleModel ? strtolower($otherKey) : $otherKey, $relation);
 }
开发者ID:hunglmtb,项目名称:eb,代码行数:4,代码来源:DynamicModel.php

示例2: belongsTo

 public function belongsTo($string = null, $foreign_key = null, $other_key = null, $relation = null)
 {
     if (is_null($relation)) {
         $backtrace = debug_backtrace(false, 5);
         $caller = $backtrace[4];
         $relation = snake_case($caller['function']);
     }
     return parent::belongsTo($string, $foreign_key, $other_key, $relation);
 }
开发者ID:kevupton,项目名称:ethereal,代码行数:9,代码来源:Ethereal.php

示例3: belongsTo

 /**
  * Override for different naming convention
  *
  * @param  string $related
  * @param  string $foreignKey
  * @param  string $otherKey
  * @param  string $relation
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  */
 public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
 {
     // If no relation name was given, we will use this debug backtrace to extract
     // the calling method's name and use that as the relationship name as most
     // of the time this will be what we desire to use for the relationships.
     if (is_null($relation)) {
         list($current, $caller) = debug_backtrace(false, 2);
         $relation = $caller['function'];
     }
     $specialType = $this->getCmsSpecialRelationType($relation);
     // If no foreign key was supplied, we can use a backtrace to guess the proper
     // foreign key name by using the name of the relationship function, which
     // when combined with an "_id" should conventionally match the columns.
     if (is_null($foreignKey)) {
         if ($specialType === self::RELATION_TYPE_CATEGORY) {
             $foreignKey = config('pxlcms.relations.categories.keys.category');
         } else {
             $foreignKey = Str::snake($relation);
         }
     }
     // If the relation name is the same (casing aside) as the foreign key attribute,
     // we must make sure that the foreign key property is at least a key in the
     // attributes array. If it is not, there will be recursive lookup problems
     // where the attribute is never resolved and 'property does not exist' exceptions occur.
     if (snake_case($relation) == $foreignKey && !array_key_exists($foreignKey, $this->attributes)) {
         $this->attributes[$foreignKey] = null;
     }
     /** @var Builder $belongsTo */
     $belongsTo = parent::belongsTo($related, $foreignKey, $otherKey, $relation);
     // category relation must be filtered by module id
     if ($specialType === self::RELATION_TYPE_CATEGORY) {
         $belongsTo->where(config('pxlcms.relations.categories.keys.module'), $this->getModuleNumber());
     }
     return $belongsTo;
 }
开发者ID:czim,项目名称:laravel-pxlcms,代码行数:44,代码来源:CmsModel.php

示例4: belongsTo

 /**
  * Define an inverse one-to-one or many relationship.
  *
  * @param  string  $related
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $relation
  * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  */
 public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
 {
     // If no relation name was given, we will use this debug backtrace to extract
     // the calling method's name and use that as the relationship name as most
     // of the time this will be what we desire to use for the relatinoships.
     if (is_null($relation)) {
         list(, $caller) = debug_backtrace(false);
         $relation = $caller['function'];
     }
     // Check if it is a relation with an original model.
     if (!is_subclass_of($related, 'Jenssegers\\Mongodb\\Model')) {
         return parent::belongsTo($related, $foreignKey, $otherKey, $relation);
     }
     // If no foreign key was supplied, we can use a backtrace to guess the proper
     // foreign key name by using the name of the relationship function, which
     // when combined with an "_id" should conventionally match the columns.
     if (is_null($foreignKey)) {
         $foreignKey = snake_case($relation) . '_id';
     }
     $instance = new $related();
     // Once we have the foreign key names, we'll just create a new Eloquent query
     // for the related models and returns the relationship instance which will
     // actually be responsible for retrieving and hydrating every relations.
     $query = $instance->newQuery();
     $otherKey = $otherKey ?: $instance->getKeyName();
     return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
 }
开发者ID:danielheyman,项目名称:TechDimeProjects,代码行数:36,代码来源:Model.php

示例5: children

 /**
  * an article comment belongs to an article comment child
  *
  * @class belongsTo parent::ArticleComment
  */
 public function children()
 {
     return parent::belongsTo(ArticleComment::class, 'parent_id', 'id');
 }
开发者ID:Dimimo,项目名称:Booklet,代码行数:9,代码来源:ArticleComment.php


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