/**
  * Validates the operator in an expression.
  *
  * @param string $operator
  *
  * @return bool
  *
  * @throws InvalidOperatorException
  */
 public function validateOperator($operator)
 {
     $operators = Operator::get();
     if (in_array($operator, $operators)) {
         return true;
     }
     $message = "Operator: {$operator} is invalid, and cannot be used.";
     throw new InvalidOperatorException($message);
 }
Exemple #2
0
 /**
  * Adds a where expression to the current query.
  *
  * @param array|string $field
  * @param string|null  $operator
  * @param mixed        $value
  * @param string       $boolean
  *
  * @return Builder
  */
 public function where($field, $operator = null, $value = null, $boolean = '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, $boolean);
         }
         return $this;
     }
     if (!in_array($operator, Operator::get())) {
         throw new InvalidOperatorException("Invalid operator {$operator}");
     }
     $this->wheres[] = compact('field', 'operator', 'value', 'boolean');
     return $this;
 }