I am having some trouble with where
/whereOr
queries. I want to check if fitting
and dimmability
are the same. Then the light_color_code
could be 2700K
or 2800K
. This is my current query:
if ($lightColorCode === '2800K') {
$correspondingLamps = Lamp::where(['fitting' => $fitting, 'dimmability' => $dimmable, 'light_color_code' => $lightColorCode])
->orWhere(['fitting' => $fitting, 'dimmability' => $dimmable, 'light_color_code' => '2700K'])
->get();
}
But it returns all the Lamps
where fitting
or dimmability
or the light_color_code
matches but they should all match. I don't see what is wrong with this query?
Update: As in the comments suggested I looked at: https://laravel.com/docs/5.7/queries#parameter-grouping and I created the following query:
$lamps = DB::table('lamps')
->where('fitting', '=', $fitting)
->where('dimmability', '=', $dimmable)
->where(function ($query, $lightColorCode) {
$query->where('light_color_code', '=', $lightColorCode)
->orWhere('light_color_code', '=', '2700K - 827 Zeer warm wit');
})
->get();
But this returns:
Too few arguments to function App\Http\Controllers\CompareController::App\Http\Controllers{closure}(), 1 passed and exactly 2 expected
I guess this is because I pass $lightColorCode
as parameter but I need that parameter in my where
.