Applies non-relation constraint to query.

@param Builder $builder query builder
@param string $field field name
@param string $mode determines how constraint is added to existing query ("or" or "and")
773196
protected function doApply(Builder $builder, $field, $mode = Constraint::MODE_AND)
    {
        if ($this->operator == Constraint::OPERATOR_IN) {
            $method = $mode != static::MODE_OR ? 'whereIn' : 'orWhereIn';
            $builder->$method($field, $this->value);
        } elseif ($this->operator == Constraint::OPERATOR_NOT_IN) {
            $method = $mode != static::MODE_OR ? 'whereNotIn' : 'orWhereNotIn';
            $builder->$method($field, $this->value);
        } elseif ($this->operator == Constraint::OPERATOR_NOT_NULL) {
            $method = $mode != static::MODE_OR ? 'whereNotNull' : 'orWhereNotNull';
            $builder->$method($field);
        } elseif ($this->operator == Constraint::OPERATOR_NULL) {
            $method = $mode != static::MODE_OR ? 'whereNull' : 'orWhereNull';
            $builder->$method($field);
        } else {
            $method = $mode != static::MODE_OR ? 'where' : 'orWhere';
            $builder->$method($field, $this->operator, $this->value);
        }
    }
996903
protected function setJoin(Builder $query = null)
    {
        $query = $query ?: $this->query;

        $foreignKey = $this->related->getTable().'.'.$this->related->getKeyName();

        $localKey = $this->parent->getTable().'.'.$this->secondKey;

        $query->join($this->parent->getTable(), $localKey, '=', $foreignKey);
    }
500758
public function remove(Builder $builder, Model $model) {
    $column = $model->getQualifiedSingleTableTypeColumn();

    $query = $builder->getQuery();

    $bindings = $query->getRawBindings()['where'];
    foreach ((array) $query->wheres as $key => $where) {
      // If the where clause is a single table inheritance in constraint, we will remove it from
      // the query and reset the keys on the wheres. This allows this developer to
      // include model in a relationship result set that is lazy loaded.

      if ($this->isSingleTableInheritanceConstraint($where, $column)) {
        unset($query->wheres[$key]);

        // Assume (naively) that no other scope is binding the same values as the values of our in query.
        // Not perfect but its about the best we can do without they query keeping better track of which bindings
        // belong to which where clause.
        foreach($where['values'] as $value) {
          if (($binding_key = array_search($value, $bindings)) >= 0) {
            unset($bindings[$binding_key]);
          }
        }

        $query->setBindings(array_values($bindings));
        $query->wheres = array_values($query->wheres);
      }
    }
  }
855823
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $fields = AppSettings::settings();
        foreach ($fields as $key => $value) {
            $builder->add($key, TextType::class, [
                'value' => $value,
                'required' => true,
                'constraints' => [ new Symfony\Component\Validator\Constraints\NotBlank()]
            ]);
        }
    }
389392
protected function constraintField(ConstraintFactory $where, $field, $value, $alias)
    {
        if ($field === $this->class->nodename) {
            $where->eq()->name($alias)->literal($value);
        } else {
            $where->eq()->field($alias.'.'.$field)->literal($value);
        }
    }
292046
public function constrainQuery(EloquentBuilder &$query, $relatedModel, $constraint)
	{
		//if the column hasn't been joined yet, join it
		if (!$this->validator->isJoined($query, $this->getOption('table')))
		{
			$query->join($this->getOption('table'), $relatedModel->getTable().'.'.$relatedModel->getKeyName(), '=', $this->getOption('column2'));
		}

		$query->where($this->getOption('table').'.'.$this->getOption('column'), '=', $constraint);
	}
1290502
public function apply(Builder $builder)
    {
        $sortMethod = 'sort' . studly_case($this->getField());

        if(method_exists($builder->getModel(), $sortMethod)) {
            call_user_func_array([$builder->getModel(), $sortMethod], [$builder, $this->getOrder()]);
        } else {
            $builder->orderBy($this->getField(), $this->getOrder());
        }
    }
33604
public function apply(Builder $builder, Model $model)
    {
        $column = $model->getQualifiedActiveColumn();

        $builder->where($column, true);

        $this->addWithInactive($builder);
    }
675504
public function remove(Builder $query, Model $model)
    {
        $query = $query->getQuery();

        $query->wheres = (new Collection($query->wheres))->reject(function ($where) {
            return $this->isScopeConstraint($where);
        })->values()->all();
    }
187141
protected function isFieldSearchable(Builder $builder, $field)
    {
        $searchable = $this->_getSearchableAttributes($builder);
        $notSearchable =  $this->_getNotSearchableAttributes($builder);

        $field = preg_replace('#^!#', '', $field);

        return !in_array($field, $notSearchable) && !in_array('*', $notSearchable) && (in_array($field, $searchable) || in_array('*', $searchable));
    }
1298960
protected function mappedQuery(Builder $query, $method, ArgumentBag $args)
    {
        $mapping = $this->getMappingForAttribute($args->get('column'));

        if ($this->relationMapping($mapping)) {
            return $this->mappedRelationQuery($query, $method, $args, $mapping);
        }

        $args->set('column', $mapping);

        return $query->callParent($method, $args->all());
    }
350916
public function apply(Builder $builder, Model $model) {
    $subclassTypes = array_keys($model->getSingleTableTypeMap());

    if (!empty($subclassTypes) ) {
      $builder->whereIn($model->getQualifiedSingleTableTypeColumn(), $subclassTypes);
    }
  }
259813
public function relation($name, $label, $builder = null)
    {
        if (is_null($builder)) {
            $builder = $label;
            $label = '';
        }

        return $this->addRelation($name, $builder, $label);
    }
1336582
protected function addWithoutClosed(Builder $builder): void
    {
        $builder->macro('withoutClosed', function (Builder $builder) {
            return $builder->withoutGlobalScope($this)->where('is_closed', 0);
        });
    }
516394
public function or(string $field, string $operator, string $field2)
    {
        $this->and($field, $operator, $field2);
        $this->convertToOrJunction();

        return $this;
    }
1001814
public function apply(Builder $builder, Model $model)
    {
        $columns = $model->getQualifiedOrderByColumns();

        foreach ($columns as $column => $direction) {

            $builder->orderBy($column, $direction);
        }

        $this->addUnordered($builder);
    }
357686
public function remove(Builder $builder, Model $model)
    {
        $query = $builder->getQuery();

        if (is_null($query->wheres)) {
            return;
        }

        $bindingKey = 0;

        $scopeConstraints = $this->getScopeConstraints($model);

        foreach ((array) $query->wheres as $key => $where) {
            $bindingsCount = $this->countBindings($where);

            if (in_array($where, $scopeConstraints)) {
                $this->removeWhere($query, $key);

                $this->removeBindings($query, $bindingKey, $bindingsCount);
            } else {
                $bindingKey += $bindingsCount;
            }
        }

        $query->wheres = array_values($query->wheres);
    }