I am trying to parse a query string into Eloquent that involves 'OR' statements. This is part of a much larger function that has other filters etc being applied, but I want to make an or_where group.
My confusion comes with the closure.. and how to make sure the right values are passed through. If I do as code below, it says the closure has the wrong arguments, but otherwise I cannot give it access to the $or_list variable.
($thing_query
is the query that's being built over the course of this and other functions.)
elseif (strstr($column, 'or|')){
//in format or|=tablename-id=240,tablename-id=8
$or_list = explode(',', $value);
var_dump(explode(',', $value));
$thing_query->where(function($q, $or_list)
{
$count = 0;
foreach ($or_list as $or) {
$arr = explode('=', $or);
$col = $arr[0];
$val = $arr[1];
$col = str_replace('-', '.', $col);
if($count == 0){
$q->where($col, '=', $val);
} else {
$q->or_where($col, '=', $val);
}
$count++;
}
});
}