Is there any way of translating following query(only the WHERE IN clause)
SELECT * FROM table WHERE (first, second) IN ((1,2),(2,3))
to Laravel Eloquent syntax?
I have tried passing an array as a first argument of Table::whereIn()
, but somewhere in the process(Illuminate\Database\Grammar:58) it gets passed to strtolower()
which does not accept an array.
Is there a workaround? Maybe something involving whereInExistingQuery
method?
If there isn't, do you know how to go about implementing such feature?
CLARIFICATION: previously mentioned clause means that (first = 1 AND second = 2) OR (first = 2 AND second = 3)
. Of course I can do this in nested queries foreach
ing over all pairs but I was hoping for more elegant/straightforward solution.
UPDATE: Because this query is invalid in eg. MSSQL, Oracle or sqlite, the only solution is to filter through columns and values:
$columns = ['first', 'second'];
$values = [
[
'first' => 1,
'second' => 2
],
[
'first' => 2,
'second' => 3,
]
];
Table::where(function($query) use ($columns, $values) {
foreach ($values as $valueArray) {
$query->orWhere(function($innerQuery) use ($columns, $valueArray) {
foreach ($columns as $column) {
$innerQuery->where($column, '=', $valueArray[$column]);
}
});
}
});