Have you installed the debug bar? Let you see what queries you are running and what the bottleneck is?
https://github.com/barryvdh/laravel-debugbar
Must have package for laravel.
Try this
$phones = Phone::where(function($query){
...
} //end of closure
)->whereHas('productnum')
->paginate(10);
Thank you for your answers. jacksoncharles i ll try it asap..
Firtzberg it gives me the following error when i try
})->whereHas('productnum')->paginate(10);
Argument 2 passed to Illuminate\Database\Eloquent\Builder::whereHas() must be an instance of Closure, none given, called in /home/xxx/app/controllers/PhoneController.php on line 90 and defined
My mistake. It should be ->has() instead of ->whereHas() in my code
I'm glad I was helpful.
You didn't use whereHas correctly. In your aproach the database had to check the conditions inside the query for each product separate, i.e. thousands of times for each phone, while in my code the conditions were checked only once for each phone.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community