@@ -96,7 +96,7 @@ public function applyGlobalScope($identifier, $scope)
96
96
* @param \Illuminate\Database\Eloquent\ScopeInterface|string $scope
97
97
* @return $this
98
98
*/
99
- public function removeGlobalScope ($ scope )
99
+ public function withoutGlobalScope ($ scope )
100
100
{
101
101
if (is_string ($ scope )) {
102
102
unset($ this ->scopes [$ scope ]);
@@ -118,7 +118,7 @@ public function removeGlobalScope($scope)
118
118
*
119
119
* @return $this
120
120
*/
121
- public function removeGlobalScopes ()
121
+ public function withoutGlobalScopes ()
122
122
{
123
123
$ this ->scopes = [];
124
124
@@ -461,7 +461,7 @@ public function onDelete(Closure $callback)
461
461
*/
462
462
public function getModels ($ columns = ['* ' ])
463
463
{
464
- $ results = $ this ->getQueryWithScopes ()->get ($ columns );
464
+ $ results = $ this ->loadScopes ()-> getQuery ()->get ($ columns );
465
465
466
466
$ connection = $ this ->model ->getConnectionName ();
467
467
@@ -641,7 +641,9 @@ public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', C
641
641
call_user_func ($ callback , $ query );
642
642
}
643
643
644
- return $ this ->addHasWhere ($ query , $ relation , $ operator , $ count , $ boolean );
644
+ return $ this ->addHasWhere (
645
+ $ query ->loadScopes (), $ relation , $ operator , $ count , $ boolean
646
+ );
645
647
}
646
648
647
649
/**
@@ -750,7 +752,7 @@ public function orWhereHas($relation, Closure $callback, $operator = '>=', $coun
750
752
*/
751
753
protected function addHasWhere (Builder $ hasQuery , Relation $ relation , $ operator , $ count , $ boolean )
752
754
{
753
- $ this ->mergeWheresToHas ($ hasQuery , $ relation );
755
+ $ this ->mergeModelDefinedRelationWheresToHasQuery ($ hasQuery , $ relation );
754
756
755
757
if (is_numeric ($ count )) {
756
758
$ count = new Expression ($ count );
@@ -766,14 +768,14 @@ protected function addHasWhere(Builder $hasQuery, Relation $relation, $operator,
766
768
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
767
769
* @return void
768
770
*/
769
- protected function mergeWheresToHas (Builder $ hasQuery , Relation $ relation )
771
+ protected function mergeModelDefinedRelationWheresToHasQuery (Builder $ hasQuery , Relation $ relation )
770
772
{
771
773
// Here we have the "has" query and the original relation. We need to copy over any
772
774
// where clauses the developer may have put in the relationship function over to
773
775
// the has query, and then copy the bindings from the "has" query to the main.
774
776
$ relationQuery = $ relation ->getBaseQuery ();
775
777
776
- $ hasQuery ->removeGlobalScopes ()-> mergeWheres (
778
+ $ hasQuery ->mergeWheres (
777
779
$ relationQuery ->wheres , $ relationQuery ->getBindings ()
778
780
);
779
781
@@ -805,7 +807,7 @@ public function with($relations)
805
807
$ relations = func_get_args ();
806
808
}
807
809
808
- $ eagers = $ this ->parseRelations ($ relations );
810
+ $ eagers = $ this ->parseWithRelations ($ relations );
809
811
810
812
$ this ->eagerLoad = array_merge ($ this ->eagerLoad , $ eagers );
811
813
@@ -818,7 +820,7 @@ public function with($relations)
818
820
* @param array $relations
819
821
* @return array
820
822
*/
821
- protected function parseRelations (array $ relations )
823
+ protected function parseWithRelations (array $ relations )
822
824
{
823
825
$ results = [];
824
826
@@ -835,7 +837,7 @@ protected function parseRelations(array $relations)
835
837
// We need to separate out any nested includes. Which allows the developers
836
838
// to load deep relationships using "dots" without stating each level of
837
839
// the relationship with its own key in the array of eager load names.
838
- $ results = $ this ->parseNested ($ name , $ results );
840
+ $ results = $ this ->parseNestedWith ($ name , $ results );
839
841
840
842
$ results [$ name ] = $ constraints ;
841
843
}
@@ -850,7 +852,7 @@ protected function parseRelations(array $relations)
850
852
* @param array $results
851
853
* @return array
852
854
*/
853
- protected function parseNested ($ name , $ results )
855
+ protected function parseNestedWith ($ name , $ results )
854
856
{
855
857
$ progress = [];
856
858
@@ -885,12 +887,12 @@ protected function callScope($scope, $parameters)
885
887
/**
886
888
* Get the underlying query builder instance with applied global scopes.
887
889
*
888
- * @return \Illuminate\Database\Query \Builder|static
890
+ * @return \Illuminate\Database\Eloquent \Builder|static
889
891
*/
890
- public function getQueryWithScopes ()
892
+ public function loadScopes ()
891
893
{
892
894
if (! $ this ->scopes ) {
893
- return $ this -> getQuery () ;
895
+ return $ this ;
894
896
}
895
897
896
898
$ builder = clone $ this ;
@@ -905,7 +907,7 @@ public function getQueryWithScopes()
905
907
}
906
908
}
907
909
908
- return $ builder-> getQuery () ;
910
+ return $ builder ;
909
911
}
910
912
911
913
/**
@@ -1022,7 +1024,7 @@ public function __call($method, $parameters)
1022
1024
}
1023
1025
1024
1026
if (in_array ($ method , $ this ->passthru )) {
1025
- return call_user_func_array ([$ this ->getQueryWithScopes (), $ method ], $ parameters );
1027
+ return call_user_func_array ([$ this ->loadScopes ()-> getQuery (), $ method ], $ parameters );
1026
1028
}
1027
1029
1028
1030
call_user_func_array ([$ this ->query , $ method ], $ parameters );
0 commit comments