Adldap\Query\Builder::where PHP 메소드

where() 공개 메소드

Adds a where clause to the current query.
public where ( string | array $field, string $operator = null, string $value = null, string $type = 'and' ) : Builder
$field string | array
$operator string
$value string
$type string
리턴 Builder
    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);
    }

Usage Example

예제 #1
0
 /**
  * Adds a where clause to the current query.
  *
  * @param string $field
  * @param string $operator
  * @param string $value
  *
  * @return $this
  */
 public function where($field, $operator = null, $value = null)
 {
     $this->query->where($field, $operator, $value);
     return $this;
 }