public function compileWheres(Builder $query)
{
$wheres = array();
foreach ($query->wheres as $where) {
if ('first' == $where['logic']) {
$first = $where;
//We'll handle this later
continue;
}
$method = "compileWhere{$where['type']}";
$wheres[$where['logic']][] = $query->{$method}($query, $where);
}
//Handle first item
if (isset($first)) {
$method = "compileWhere{$first['type']}";
$where = $query->{$method}($query, $first);
if (1 >= count($wheres)) {
$key = key($wheres) ?: '$and';
isset($wheres[$key]) or $wheres[$key] = array();
array_unshift($wheres[$key], $where);
} else {
throw new \Exception('More then one logical operator found on root');
}
}
return $wheres;
}