I don't know if it's possible to do but I want to be able to add to the where conditions dynamically. I think there is a way. I want to be able to send one query instead of multiple queries to the database.
Here's the code I have so far
$elements = NutritionValues::where(function($query) use ($client_id, $products) {
foreach($products as $product) {
$query->where('client_id', '=', $client_id)
->where('product_id', '=', $product['product_id'])
->where('ingredient_name', '=', $product['element_name']);
}
})->get();
return $elements;
Your query looks good, but the data you are using to build it may give you an invalid result. Add this command before your query:
DB::listen(function($sql, $bindings, $time) {
var_dump($sql);
var_dump($bindings);
});
to show in your page or
DB::listen(function($sql, $bindings, $time) {
Log::info($sql);
Log::info($bindings);
});
to send to log.
It will display the generated query and the values (bindings) used to execute it. Analyse it and execute it in your cli, or whatever program you have to connect directly to your database server.