本文整理汇总了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));
}
示例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());
}
}
示例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())));
}
示例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())));
}
示例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;
}
示例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);
}
示例7: getOrderColumn
/**
* @param Builder $query
*/
private function getOrderColumn($query)
{
if ($this->column instanceof Expression) {
return $this->column;
}
return $query->getModel()->getTable() . '.' . $this->column;
}
示例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';
}
示例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());
}
}
示例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);
}
示例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);
}
}
}
示例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();
}
示例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);
}
}
}
示例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;
});
}
示例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;
});
}