/** * Get an array of global scopes that were removed from the query. * * @return array * @static */ public static function removedScopes() { return \Illuminate\Database\Eloquent\Builder::removedScopes(); }
/** * Merge the constraints from a relation query to the current query. * * @param \Illuminate\Database\Eloquent\Builder $relation * @return \Illuminate\Database\Eloquent\Builder|static */ public function mergeModelDefinedRelationConstraints(Builder $relation) { $removedScopes = $relation->removedScopes(); $relationQuery = $relation->getQuery(); // 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, $relationQuery->getBindings()); }
/** * Merge the "wheres" from a relation query to a has query. * * @param \Illuminate\Database\Eloquent\Builder $hasQuery * @param \Illuminate\Database\Eloquent\Relations\Relation $relation * @return void */ protected function mergeModelDefinedRelationWheresToHasQuery(Builder $hasQuery, Relation $relation) { $removedScopes = $hasQuery->removedScopes(); $relationQuery = $relation->withoutGlobalScopes($removedScopes)->toBase(); // Here we have the "has" query and the original relation. We need to copy over any // where clauses the developer may have put in the relationship function over to // the has query, and then copy the bindings from the "has" query to the main. $hasQuery->withoutGlobalScopes()->mergeWheres($relationQuery->wheres, $relationQuery->getBindings()); }