public function where($field, $operator = null, $value = null, $type = 'and')
{
if (is_array($field)) {
// If the column is an array, we will assume it is an array of
// key-value pairs and can add them each as a where clause.
foreach ($field as $key => $value) {
$this->where($key, Operator::$equals, $value, $type);
}
return $this;
}
// We'll bypass the 'has' and 'notHas' operator since they
// only require two arguments inside the where method.
$bypass = [Operator::$has, Operator::$notHas];
// Here we will make some assumptions about the operator. If only 2 values are
// passed to the method, we will assume that the operator is an equals sign
// and keep going.
if (func_num_args() === 2 && in_array($operator, $bypass) === false) {
list($value, $operator) = [$operator, '='];
}
// We'll construct a new where binding.
$binding = $this->newWhereBinding($field, $operator, $value, $type);
// Normalize type.
$type = $type == 'or' ? 'orWhere' : 'where';
// Then add it to the current query builder.
return $this->addBinding($binding, $type);
}