In an eloquent query I am building, I am placing a constraint on a has
relationship using Laravel 4.1\'s whereHas
and orWhereHas
metho
You need to reference the query passed through to the where closure. Otherwise you are adding the grouped where clauses to the main query bypassing any groupings:
$ret
->where( function( $query ){
$query->whereHas('homeClub', function ( $subquery ){
$subquery->where('name','Arsenal' );
})
->orWhereHas('awayClub',function ( $subquery ){
$subquery->where('name','Arsenal' );
});
})
->where( function ( $query ) use ( $parameterValues ){
$query->whereHas('season', function ($subquery) use ( $parameterValues ){
$subquery->where('name', $parameterValues['season_names'] );
});
})
->whereHas('territory',function( $query ) use ( $parameterValues ){
$query->where('region','Australia');
})
->get();