To get an SQL Statement like this;
SELECT postcode FROM Payment WHERE
countries IN ('E92000001', 'L93000001') AND
counties IN ('95', 'E10000002') AND
gors in ('A', 'B');
My code is currently;
$postcode_extract = PostcodeExtract::all();
foreach ($input as $column => $values) {
$postcode_extract->whereIn($column, $values);
}
I need to switch those ANDs to ORs. I think I might have it;
foreach ($input as $column => $values) {
$postcode_extract->orWhere(function ($query) use ($column, $values) {
$query->whereIn($column, $values);
});
}
I do get results.. It's hard to tell without seeing the raw query though. I used toSql()
and this is the result;
select * from `201502_postcode` where (`country` in (?, ?)) or (`county` in (?, ?)) or (`gor` in (?, ?))
Why the ?
s though? Why not the real data or is that not how toSql
works?
-- UPDATE --
Here is my code using toSql
;
$sql = $postcode_extract->toSql();
print_r($sql);
I do it after the foreach loop