本文整理汇总了PHP中Illuminate\Database\Eloquent\Relations\Relation::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Relation::getQuery方法的具体用法?PHP Relation::getQuery怎么用?PHP Relation::getQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Relations\Relation
的用法示例。
在下文中一共展示了Relation::getQuery方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: getRelationshipWheres
/**
* Sets up the existing relationship wheres.
*
* @param \Illuminate\Database\Eloquent\Relations\Relation $relationship
* @param string $tableAlias
* @param string $pivotAlias
* @param string $pivot
*
* @return string
*/
public function getRelationshipWheres($relationship, $tableAlias, $pivotAlias = null, $pivot = null)
{
//get the relationship model
$relationshipModel = $relationship->getRelated();
//get the query instance
$query = $relationship->getQuery()->getQuery();
//get the connection instance
$connection = $query->getConnection();
//one element of the relationship query's wheres is always useless (it will say pivot_table.other_id is null)
//depending on whether or not softdeletes are enabled on the other model, this will be in either position 0
//or 1 of the wheres array
array_splice($query->wheres, method_exists($relationshipModel, 'getDeletedAtColumn') ? 1 : 0, 1);
//iterate over the wheres to properly alias the columns
foreach ($query->wheres as &$where) {
//alias the where columns
$where['column'] = $this->aliasRelationshipWhere($where['column'], $tableAlias, $pivotAlias, $pivot);
}
$sql = $query->toSql();
$fullQuery = $this->interpolateQuery($sql, $connection->prepareBindings($query->getBindings()));
$split = explode(' where ', $fullQuery);
return isset($split[1]) ? $split[1] : '';
}
示例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|static
*/
protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator, $count, $boolean)
{
$hasQuery->mergeModelDefinedRelationConstraints($relation->getQuery());
if ($this->shouldRunExistsQuery($operator, $count)) {
$not = $operator === '<' && $count === 1;
return $this->addWhereExistsQuery($hasQuery->toBase(), $boolean, $not);
}
return $this->whereCountQuery($hasQuery->toBase(), $operator, $count, $boolean);
}