Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

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() ) );

0

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...

Last updated 9 years ago.
0

Found the solution:

$query1 = Person::whereHas("country", function($query) {
				$query->where(function($query) {
					$query->where("code", '=', "EN");
					$query->orWhere("code", '=', "AU");
				});
			});
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.