Illuminate\Database\Eloquent\Builder::mergeModelDefinedRelationConstraints PHP Метод

mergeModelDefinedRelationConstraints() публичный Метод

Merge the constraints from a relation query to the current query.
public mergeModelDefinedRelationConstraints ( Builder $relation ) : Builder | static
$relation Builder
Результат Builder | static
    public function mergeModelDefinedRelationConstraints(Builder $relation)
    {
        $removedScopes = $relation->removedScopes();
        $relationQuery = $relation->getQuery();
        $whereBindings = Arr::get($relationQuery->getRawBindings(), 'where', []);
        // Here we have some relation query and the original relation. We need to copy over any
        // where clauses that the developer may have put in the relation definition function.
        // We need to remove any global scopes that the developer already removed as well.
        return $this->withoutGlobalScopes($removedScopes)->mergeWheres($relationQuery->wheres, $whereBindings);
    }

Usage Example

Пример #1
0
 /**
  * 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);
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::mergeModelDefinedRelationConstraints