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