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


PHP Relations\Relation类代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Relations\Relation的典型用法代码示例。如果您正苦于以下问题:PHP Relation类的具体用法?PHP Relation怎么用?PHP Relation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: boot

 /**
  * Boot the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     Relation::morphMap(['quran_recordings' => \Modules\Quran\Entities\QuranRecording::class]);
 }
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:QuranServiceProvider.php

示例2: boot

 /**
  * Boot the application events.
  *
  * @return void
  */
 public function boot(Router $router)
 {
     $router->model('uuser', '\\Modules\\Users\\Entities\\User');
     $router->model('urole', '\\Bican\\Roles\\Models\\Role');
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     Relation::morphMap(['users' => \Modules\Users\Entities\User::class]);
 }
开发者ID:hisambahaa,项目名称:DARES,代码行数:14,代码来源:UsersServiceProvider.php

示例3: addHasWhere

 /**
  * Add the "has" condition where clause to the query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $hasQuery
  * @param  \Illuminate\Database\Eloquent\Relations\Relation  $relation
  * @param  string  $operator
  * @param  int  $count
  * @param  string  $boolean
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean)
 {
     $query = $hasQuery->getQuery();
     // Get the number of related objects for each possible parent.
     $relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
     // Remove unwanted related objects based on the operator and count.
     $relationCount = array_filter($relationCount, function ($counted) use($count, $operator) {
         // If we are comparing to 0, we always need all results.
         if ($count == 0) {
             return true;
         }
         switch ($operator) {
             case '>=':
             case '<':
                 return $counted >= $count;
             case '>':
             case '<=':
                 return $counted > $count;
             case '=':
             case '!=':
                 return $counted == $count;
         }
     });
     // If the operator is <, <= or !=, we will use whereNotIn.
     $not = in_array($operator, array('<', '<=', '!='));
     // If we are comparing to 0, we need an additional $not flip.
     if ($count == 0) {
         $not = !$not;
     }
     // All related ids.
     $relatedIds = array_keys($relationCount);
     // Add whereIn to the query.
     return $this->whereIn($this->model->getKeyName(), $relatedIds, $boolean, $not);
 }
开发者ID:reverserob,项目名称:laravel-mongodb,代码行数:44,代码来源:Builder.php

示例4: verifyRelation

 protected function verifyRelation(ReflectionMethod $method, Relation $relationship)
 {
     $expectedRelatedModel = $this->relatedModel === get_class($relationship->getRelated());
     $expectedRelationName = get_class($relationship) === $this->type;
     $expectedReturnAnnotation = $this->getReturnAnnotation($method) === $this->type;
     return $expectedRelationName && $expectedRelatedModel && $expectedReturnAnnotation;
 }
开发者ID:fs-ap,项目名称:laravel-relationship-test,代码行数:7,代码来源:Relationship.php

示例5: deleteAllRelatedExcept

 /**
  * @param Relation $relation
  * @param array    $excluded_ids
  */
 public static function deleteAllRelatedExcept(Relation $relation, $excluded_ids = [])
 {
     $related = $relation->getRelated();
     $key_name = $related->getKeyName();
     $query = $relation->getQuery();
     if (count($excluded_ids) > 0) {
         $query->whereNotIn($key_name, $excluded_ids);
     }
     $query->delete();
 }
开发者ID:exolnet,项目名称:laravel-module,代码行数:14,代码来源:Helper.php

示例6: addJoinToQuery

 /**
  * @param $joinTableAlias
  * @param $currentTableAlias
  * @param BelongsTo|Relation $relation
  * @param string $columnsPrefix
  */
 protected function addJoinToQuery($joinTableAlias, $currentTableAlias, Relation $relation, $columnsPrefix = '')
 {
     $joinTableName = $relation->getRelated()->getTable();
     $joinTable = implode(' as ', [$joinTableName, $joinTableAlias]);
     $joinLeftCondition = implode('.', [$joinTableAlias, $relation->getOtherKey()]);
     $joinRightCondition = implode('.', [$currentTableAlias, $relation->getForeignKey()]);
     $this->query->leftJoin($joinTable, $joinLeftCondition, '=', $joinRightCondition);
     $columns = $this->getColumns($joinTableName);
     $prefix = static::$prefix . $columnsPrefix . $joinTableAlias . '---';
     foreach ($columns as $column) {
         $this->selectFromQuery($joinTableAlias, $column, $prefix . $column);
     }
 }
开发者ID:leloulight,项目名称:trigglog,代码行数:19,代码来源:WithJoinEloquentBuilder.php

示例7: __construct

 public function __construct(array $config, ModelManager $modelManager, Model $model, EloquentRelation $eloquentRelation, FieldFactory $fieldFactory)
 {
     $this->checkNameConfig($config);
     $this->name = $config['name'];
     $this->slug = $config['name'];
     $this->relatedModel = $model;
     $this->eloquentRelation = $eloquentRelation;
     $this->fieldFactory = $fieldFactory;
     $this->modelManager = $modelManager;
     $this->config = $config;
     $this->setup();
     $this->modelAbstractor = \App::make('Anavel\\Crud\\Contracts\\Abstractor\\ModelFactory')->getByClassName(get_class($this->eloquentRelation->getRelated()), $this->config);
 }
开发者ID:ablunier,项目名称:crud,代码行数:13,代码来源:Relation.php

示例8: __construct

 /**
  * DescendantsRelation constructor.
  *
  * @param QueryBuilder $builder
  * @param Model $model
  */
 public function __construct(QueryBuilder $builder, Model $model)
 {
     if (!NestedSet::isNode($model)) {
         throw new InvalidArgumentException('Model must be node.');
     }
     parent::__construct($builder, $model);
 }
开发者ID:nutsdo,项目名称:nong-store,代码行数:13,代码来源:DescendantsRelation.php

示例9: boot

 /**
  * Boot the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     Relation::morphMap(['paper_doc' => \Modules\Papers\Entities\PaperDoc::class, 'paper_semster_doc' => \Modules\Papers\Entities\PaperSemesterDoc::class]);
 }
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:PapersServiceProvider.php

示例10: boot

 /**
  * Boot the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     Relation::morphMap(['order_quran_excuses' => \Modules\Orders\Entities\OrderQuranExcuse::class]);
 }
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:OrdersServiceProvider.php

示例11: getRelationCountQuery

 /**
  * Add the constraints for a relationship count query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Builder  $parent
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function getRelationCountQuery(Builder $query, Builder $parent)
 {
     if ($parent->getQuery()->from == $query->getQuery()->from) {
         return $this->getRelationCountQueryForSelfRelation($query, $parent);
     }
     return parent::getRelationCountQuery($query, $parent);
 }
开发者ID:nsoimaru,项目名称:Laravel51-starter,代码行数:14,代码来源:HasOneOrMany.php

示例12: boot

 /**
  * Boot the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     Relation::morphMap(['teachers' => \Modules\Teachers\Entities\Teacher::class]);
 }
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:TeachersServiceProvider.php

示例13: getRelationQuery

 /**
  * Add the constraints for a relationship query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Builder  $parent
  * @param  array|mixed  $columns
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
 {
     if ($parent->getQuery()->from == $query->getQuery()->from) {
         return $this->getRelationQueryForSelfRelation($query, $parent, $columns);
     }
     return parent::getRelationQuery($query, $parent, $columns);
 }
开发者ID:bryanashley,项目名称:framework,代码行数:15,代码来源:HasOneOrMany.php

示例14: boot

 /**
  * Boot the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     Relation::morphMap([]);
 }
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:ExamsServiceProvider.php

示例15: __construct

 /**
  * Create a new has many relationship instance.
  *
  * @param  Illuminate\Database\Eloquent\Builder  $query
  * @param  Illuminate\Database\Eloquent\Model  $parent
  * @param  string  $table
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $table, $foreignKey, $otherKey)
 {
     $this->table = $table;
     $this->otherKey = $otherKey;
     $this->foreignKey = $foreignKey;
     parent::__construct($query, $parent);
 }
开发者ID:hochanh,项目名称:Bootsoft-Bowling,代码行数:17,代码来源:BelongsToMany.php


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