Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on cutting down database queries for a recommended product #2

Open
dniccum opened this issue Feb 8, 2018 · 0 comments
Open

Comments

@dniccum
Copy link

dniccum commented Feb 8, 2018

I have one question though, that could be more of a philosophical question.

In this application I am recommending a product (which exists in a table within the database) based the results of a "quiz" that the user takes (also exists within the database). Within the user's dashboard there could be 30, 40 or even more quizzes; all requiring the name of the recommended product to be visible. The catch is, I am not referring to these products by a foreign key. I am building a search query based on the results that the user inputs during the quiz. See below:

$recommendedProducts = Product::where('location', 'LIKE', '%'.$location.'%')
    ->whereIn('installed_in_traffic_area', $installationInTrafficDef)
    ->where('flow_rate', '>=', $flowRate)
    ->where('grease_capacity', '>=', $pumpCycleCapacity)->get();

Is there a way to cut down on my database queries using scopes, eager loading, or whatever, to retrieve the related product without having to query my database for every single quiz? My initial thought was no, but after seeing/hearing your talk I am now wondering if my initial thought was incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant