I have no idea why this would happen but you can dump the querylog and check it out
$queries = DB::getQueryLog();
$queries is then an array that you can print_r or whatever to see what's going on. or if you just want the last query then something like
print_r( end( DB::getQueryLog() ) );
Kpzani has made a valid suggestion, this will give you further clues on what might be wrong.
I believe that you can not use multiple 'where' clauses in a 'where' condition of your 'has' clause... sorry for the confusing explanation. I will show with an example (and please notice that the 'whereHas' as well as the 'orWhereHas' have both '$query->where')
Use this
$query1 = Person::whereHas("country", function($query) {
$query->where("code", '=', "EN");
})->orWhereHas("country", function($query) {
$query->where("code", '=', "AU");
})->get();
instead of this
$query1 = Person::whereHas("country", function($query) {
$query->where("code", '=', "EN");
$query->orWhere("code", '=', "AU");
});
And if I am not mistaken, you are missing in both examples the 'find' method, i.e. an 'all()', 'find()' or a 'get()' at the end of the query. It is strange that you even get results with your queries...
Found the solution:
$query1 = Person::whereHas("country", function($query) {
$query->where(function($query) {
$query->where("code", '=', "EN");
$query->orWhere("code", '=', "AU");
});
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community