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


PHP Builder::getModel方法代码示例

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


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

示例1: getRelationCountQueryForSelfRelation

 /**
  * Add the constraints for a relationship count query on the same table.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Builder  $parent
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent)
 {
     $query->select(new Expression('count(*)'));
     $query->from($query->getModel()->getTable() . ' as ' . ($hash = $this->getRelationCountHash()));
     $query->getModel()->setTable($hash);
     $key = $this->wrap($this->getQualifiedParentKeyName());
     return $query->where($hash . '.' . $this->getPlainForeignKey(), '=', new Expression($key));
 }
开发者ID:laerciobernardo,项目名称:CodeDelivery,代码行数:15,代码来源:HasOneOrMany.php

示例2: apply

 /**
  * Applies criterion to query.
  *
  * @param Builder $builder query builder
  */
 public function apply(Builder $builder)
 {
     $sortMethod = 'sort' . studly_case($this->getField());
     if (method_exists($builder->getModel(), $sortMethod)) {
         call_user_func_array([$builder->getModel(), $sortMethod], [$builder, $this->getOrder()]);
     } else {
         $builder->orderBy($this->getField(), $this->getOrder());
     }
 }
开发者ID:bdsoha,项目名称:sortable,代码行数:14,代码来源:Criterion.php

示例3: _getWithableRelations

 /**
  * @return array list of relations that can be eagerly loaded
  */
 protected function _getWithableRelations(Builder $builder)
 {
     if (method_exists($builder->getModel(), 'getWithableRelations')) {
         return $builder->getModel()->getWithableRelations();
     }
     if (property_exists($builder->getModel(), 'withable')) {
         return $builder->getModel()->withable;
     }
     throw new RuntimeException(sprintf('Model %s must either implement getWithableRelations() or have $withable property set', get_class($builder->getModel())));
 }
开发者ID:jedrzej,项目名称:withable,代码行数:13,代码来源:WithableTrait.php

示例4: _getSortableAttributes

 /**
  * @param Builder $builder
  *
  * @return array list of sortable attributes
  */
 protected function _getSortableAttributes(Builder $builder)
 {
     if (method_exists($builder->getModel(), 'getSortableAttributes')) {
         return $builder->getModel()->getSortableAttributes();
     }
     if (property_exists($builder->getModel(), 'sortable')) {
         return $builder->getModel()->sortable;
     }
     throw new RuntimeException(sprintf('Model %s must either implement getSortableAttributes() or have $sortable property set', get_class($builder->getModel())));
 }
开发者ID:jedrzej,项目名称:sortable,代码行数:15,代码来源:SortableTrait.php

示例5: initialize

 /**
  * Initialize
  *
  * @return void
  */
 public function initialize()
 {
     if (!$this->initialized) {
         $query = $this->builder->toBase();
         $sql = $query->toSql();
         $bindings = $query->getBindings();
         $conn = $query->getConnection();
         $this->statement = $conn->getPdo()->prepare($sql);
         $this->statement->execute($conn->prepareBindings($bindings));
         $this->prototype = $this->builder->getModel()->newFromBuilder();
     }
     $this->initialized = true;
 }
开发者ID:naturalweb,项目名称:nwlaravel,代码行数:18,代码来源:BuilderResultset.php

示例6: search

 /**
  * @param Model|Builder $model
  * @return Model
  */
 public function search($model)
 {
     if ($model instanceof SearchableModel) {
         $this->fieldConfig = $model->searchableFields();
         $this->primaryTable = $model->getTable();
     }
     if ($model instanceof Relation) {
         $this->primaryTable = $model->getModel()->getTable();
         $this->fieldConfig = $model->getModel()->searchableFields();
         $this->apply($model->getQuery());
         return $model;
     }
     return $this->apply($model);
 }
开发者ID:theHarvester,项目名称:QURI-Laravel,代码行数:18,代码来源:QuriRequest.php

示例7: getOrderColumn

 /**
  * @param Builder $query
  */
 private function getOrderColumn($query)
 {
     if ($this->column instanceof Expression) {
         return $this->column;
     }
     return $query->getModel()->getTable() . '.' . $this->column;
 }
开发者ID:windqyoung,项目名称:utils,代码行数:10,代码来源:OrderBy.php

示例8: getPrimaryKeyName

 /**
  * If column name could not be resolved then use primary key.
  *
  * @return string
  */
 protected function getPrimaryKeyName()
 {
     if ($this->isEloquent()) {
         return $this->query->getModel()->getKeyName();
     }
     return 'id';
 }
开发者ID:rikardote,项目名称:agenda,代码行数:12,代码来源:BaseEngine.php

示例9: apply

 /**
  * Applies filter to given query
  *
  * @param Builder $queryBuilder
  */
 public function apply(Builder $queryBuilder)
 {
     if ($this->value()) {
         $related = $this->list->getCallable($queryBuilder->getModel(), $this->field, false);
         $queryBuilder->where($this->qualifiedFieldName($related, $related->getKeyName()), $this->value());
     }
 }
开发者ID:unxp,项目名称:laralist,代码行数:12,代码来源:Foreign.php

示例10: __construct

 /**
  * Create a new morph to many relationship instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $parent
  * @param  string  $name
  * @param  string  $table
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $relationName
  * @param  bool  $inverse
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false)
 {
     $this->inverse = $inverse;
     $this->morphType = $name . '_type';
     $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
     parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName);
 }
开发者ID:manhvu1212,项目名称:videoplatform,代码行数:20,代码来源:MorphToMany.php

示例11: generateFromRelations

 public function generateFromRelations()
 {
     $this->parent = $this->query->getModel();
     foreach (explode('.', $this->relations) as $index => $relation) {
         $this->index = $index;
         $this->relation = call_user_func(array($this->parent, $relation));
         $this->related = $this->relation->getRelated();
         if ($this->nested) {
             if (!array_key_exists($this->index, $this->ons)) {
                 $this->ons[$this->index] = [];
             }
             if (!array_key_exists($this->index, $this->conditions)) {
                 $this->conditions[$this->index] = [];
             }
         }
         if ($this->relation instanceof BelongsTo) {
             $this->generateJoinFromBelongsTo($this->relation);
         } elseif ($this->relation instanceof BelongsToMany) {
             $this->generateJoinFromBelongsToMany($this->relation);
         } elseif ($this->relation instanceof HasOneOrMany) {
             $this->generateJoinFromHasOneOrMany($this->relation);
         }
         $this->parent = $this->relation->getRelated();
     }
     if ($this->addNullCondition) {
         if ($this->relation instanceof BelongsTo) {
             $this->generateNullConditionFromBelongsTo($this->relation);
         } elseif ($this->relation instanceof BelongsToMany) {
             $this->generateNullConditionFromBelongsToMany();
         } elseif ($this->relation instanceof HasOneOrMany) {
             $this->generateNullConditionFromHasOneOrMany($this->relation);
         }
     }
 }
开发者ID:brazenvoid,项目名称:better-eloquent,代码行数:34,代码来源:JoinBuilder.php

示例12: __construct

 /**
  * Create a new relation instance.
  *
  * @param  Illuminate\Database\Eloquent\Builder
  * @param  Illuminate\Database\Eloquent\Model
  * @return void
  */
 public function __construct(Builder $query, Model $parent)
 {
     $this->query = $query;
     $this->parent = $parent;
     $this->related = $query->getModel();
     $this->addConstraints();
 }
开发者ID:hochanh,项目名称:Bootsoft-Bowling,代码行数:14,代码来源:Relation.php

示例13: apply

 /**
  * @param Builder $builder
  * @param Model   $model
  */
 public function apply(Builder $builder, Model $model)
 {
     if (!Auth::guest() && Auth::user()->hasCountryRole()) {
         $country = Auth::user()->country;
         if ($builder->getModel()->getTable() == "activity_logs") {
             $builder->whereHas('contract', function ($q) use($country) {
                 $q->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
             });
         } elseif ($builder->getModel()->getTable() == "contract_annotations") {
             $builder->whereHas('contract', function ($q) use($country) {
                 $q->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
             });
         } else {
             $builder->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
         }
     }
 }
开发者ID:sadhakbj,项目名称:resourcecontracts.org,代码行数:21,代码来源:CountryScope.php

示例14: addOnlyOffline

 /**
  * Add the only-trashed extension to the builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @return void
  */
 protected function addOnlyOffline(Builder $builder)
 {
     $builder->macro('onlyOffline', function (Builder $builder) {
         $model = $builder->getModel();
         $builder->withoutGlobalScope($this)->where($model->getQualifiedStatusColumn(), '=', false);
         return $builder;
     });
 }
开发者ID:SchizoDuckie,项目名称:Expendable,代码行数:14,代码来源:StatusScope.php

示例15: addOnlyOldVersions

 /**
  * @param Builder $builder
  */
 protected function addOnlyOldVersions(Builder $builder)
 {
     $builder->macro('onlyOldVersions', function (Builder $builder) {
         $model = $builder->getModel();
         $builder->withoutGlobalScope($this)->where($model->getQualifiedIsCurrentVersionColumn(), 0);
         return $builder;
     });
 }
开发者ID:sbarre,项目名称:eloquent-versioned,代码行数:11,代码来源:VersioningScope.php


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