Пример #1
0
 /**
  * Add a basic where clause to the query.
  *
  * @param  string|array|\Closure  $column
  * @param  string  $operator
  * @param  mixed   $value
  * @param  string  $boolean
  * @return $this
  *
  * @throws \InvalidArgumentException
  */
 public function where($column, $operator = null, $value = null, $boolean = 'and')
 {
     // 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. We will maintain the boolean we
     // received when the method was called and pass it into the nested where.
     if (is_array($column)) {
         return $this->addArrayOfWheres($column, $boolean);
     }
     // 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. Otherwise, we'll require the operator to be passed in.
     if (func_num_args() == 2) {
         list($value, $operator) = [$operator, '='];
     } elseif ($this->invalidOperatorAndValue($operator, $value)) {
         throw new InvalidArgumentException('Illegal operator and value combination.');
     }
     // If the columns is actually a Closure instance, we will assume the developer
     // wants to begin a nested where statement which is wrapped in parenthesis.
     // We'll add that Closure to the query then return back out immediately.
     if ($column instanceof Closure) {
         return $this->whereNested($column, $boolean);
     }
     // If the given operator is not found in the list of valid operators we will
     // assume that the developer is just short-cutting the '=' operators and
     // we will set the operators to '=' and set the values appropriately.
     if (!in_array(strtolower($operator), $this->operators, true) && !in_array(strtolower($operator), $this->grammar->getOperators(), true)) {
         list($value, $operator) = [$operator, '='];
     }
     // If the value is a Closure, it means the developer is performing an entire
     // sub-select within the query and we will need to compile the sub-select
     // within the where clause to get the appropriate query record results.
     if ($value instanceof Closure) {
         return $this->whereSub($column, $operator, $value, $boolean);
     }
     // If the value is "null", we will just assume the developer wants to add a
     // where null clause to the query. So, we will allow a short-cut here to
     // that method for convenience so the developer doesn't have to check.
     if (is_null($value)) {
         return $this->whereNull($column, $boolean, $operator != '=');
     }
     // Now that we are working with just a simple query we can put the elements
     // in our array and add the query binding to our array of bindings that
     // will be bound to each SQL statements when it is finally executed.
     $type = 'Basic';
     $this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean');
     if (!$value instanceof Expression) {
         $this->addBinding($value, 'where');
     }
     return $this;
 }
 /**
  * Add a "where" clause comparing two columns to the query.
  *
  * @param  string|array  $first
  * @param  string|null  $operator
  * @param  string|null  $second
  * @param  string|null  $boolean
  * @return \Illuminate\Database\Query\Builder|static
  */
 public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
 {
     // 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. We will maintain the boolean we
     // received when the method was called and pass it into the nested where.
     if (is_array($first)) {
         return $this->addArrayOfWheres($first, $boolean, 'whereColumn');
     }
     // If the given operator is not found in the list of valid operators we will
     // assume that the developer is just short-cutting the '=' operators and
     // we will set the operators to '=' and set the values appropriately.
     if (!in_array(strtolower($operator), $this->operators, true) && !in_array(strtolower($operator), $this->grammar->getOperators(), true)) {
         list($second, $operator) = [$operator, '='];
     }
     $type = 'Column';
     $this->wheres[] = compact('type', 'first', 'operator', 'second', 'boolean');
     return $this;
 }