本文整理汇总了PHP中Illuminate\Database\Query\Builder::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::where方法的具体用法?PHP Builder::where怎么用?PHP Builder::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: where
/**
* {@inheritdoc}
*/
public function where(Builder $query, $value, $operator = '=')
{
if ($value === self::NULL_VALUE) {
$value = null;
}
return $query->where($this->initQuery($query), $operator, $value);
}
示例2: scopeOfType
/**
* @param \Illuminate\Database\Query\Builder $query
* @param string $type
*
* @return \Illuminate\Database\Query\Builder
* @throws \Exception
*/
public function scopeOfType($query, $type = 'image')
{
if (!in_array($type, ['plain', 'image', 'audio', 'video', 'application'])) {
throw new \Exception();
}
return $query->where('mime', 'like', $type . '/%');
}
示例3: scopeFindByRequest
/**
* Find by conditions in request
*
* @param Builder $query
* @param array|null $request
* @return \Illuminate\Database\Query\Builder
*/
public function scopeFindByRequest($query, $request = NULL)
{
if (is_null($request)) {
$request = Input::all();
}
$findable = isset($this->findable) ? $this->findable : [];
foreach ($request as $field => $value) {
if (!in_array($field, $findable)) {
continue;
}
if ($field == 'tag') {
if (isset($request['tag_search']) && $request['tag_search'] == 'any') {
$query->withAnyTag($value);
} else {
$query->withAllTags($value);
}
continue;
}
if (is_array($value)) {
$query->whereIn($field, $value);
} elseif (is_scalar($value)) {
$query->where($field, '=', $value);
}
}
}
示例4: scopeCategory
/**
* Eloquent Scope for tag categories.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $category
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeCategory($query, $category)
{
if (!is_null($category)) {
return $query->where('category', '=', $category);
}
return $query;
}
示例5: execute
public function execute(Builder $query)
{
$isWhere = false;
$count = 0;
foreach ($this->getValuesIterator() as $where) {
$operator = $where->getOperator();
if (array_key_exists($operator, WhereValidator::$especial_operator)) {
$method = $where->getOperatorValue();
switch ($method) {
case WhereValidator::$especial_operator['isNull']:
case WhereValidator::$especial_operator['isNotNull']:
$query->{$method}($where->getName());
break;
case WhereValidator::$especial_operator['between']:
case WhereValidator::$especial_operator['in']:
$query->{$method}($where->getName(), $where->getValue());
break;
}
continue;
} else {
if ($where->getOperatorValue() == WhereValidator::$operator['like']) {
$value = '%' . $where->getValue() . '%';
} else {
$value = $where->getValue();
}
}
$query->where($where->getName(), $where->getOperatorValue(), $value);
}
return $query;
}
示例6: constrainByModel
/**
* Constrain a query to an ability for a specific model.
*
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
* @param \Illuminate\Database\Eloquent\Model $model
* @param bool $strict
* @return void
*/
protected function constrainByModel($query, Model $model, $strict = false)
{
$query->where(function ($query) use($model, $strict) {
$query->where($this->table . '.entity_type', $model->getMorphClass());
$query->where($this->abilitySubqueryConstraint($model, $strict));
});
}
示例7: find
/**
* Find a model by its primary key.
*
* @param mixed $id
* @param array $columns
* @return \Illuminate\Database\Eloquent\Model|static|null
*/
public function find($id, $columns = array('*'))
{
if (is_array($id)) {
return $this->findMany($id, $columns);
}
$this->query->where($this->model->getQualifiedKeyName(), '=', $id);
return $this->first($columns);
}
示例8: it_load_events_for_aggregate
/**
* @test
*/
public function it_load_events_for_aggregate()
{
$aggregateRootId = new BarId('BarId');
$this->db->table('events')->willReturn($this->queryBuilder);
$this->queryBuilder->where('aggregate_root_id', 'BarId')->willReturn($this->queryBuilder);
$this->queryBuilder->chunk(1000, Argument::any())->willReturn(true);
$this->eventStore->load($aggregateRootId);
}
示例9: apply
/**
* Modify a Builder object. Changes here can be nested
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder $query
*/
public function apply(\Illuminate\Database\Query\Builder $query)
{
//modify $query here
if ($this->minAge) {
$query->where('test_users.dob', '<=', Carbon::now()->subYears($this->minAge)->toDateTimeString());
}
if ($this->maxAge) {
$query->where('test_users.dob', '>=', Carbon::now()->subYears($this->maxAge)->toDateTimeString());
}
return $query;
}
示例10: addWhere
/**
* Add a "where" clause to the given query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $key
* @param string $extraValue
* @return void
*/
protected function addWhere($query, $key, $extraValue)
{
if ($extraValue === 'NULL') {
$query->whereNull($key);
} elseif ($extraValue === 'NOT_NULL') {
$query->whereNotNull($key);
} elseif (Str::startsWith($extraValue, '!')) {
$query->where($key, '!=', mb_substr($extraValue, 1));
} else {
$query->where($key, $extraValue);
}
}
示例11: scopeForModel
/**
* Constrain a query to an ability for a specific model.
*
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function scopeForModel($query, Model $model)
{
$query->where(function ($query) use($model) {
$query->where('entity_type', $model->getMorphClass());
$query->where(function ($query) use($model) {
$query->whereNull('entity_id');
if ($model->exists) {
$query->orWhere('entity_id', $model->getKey());
}
});
});
}
示例12: applyAnd
/**
* Call apply() within an "and" block
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder $query
*/
public function applyAnd(\Illuminate\Database\Query\Builder $query)
{
$query->where(function ($query) {
$this->apply($query);
});
return $query;
}
示例13: parseFullTextSearch
/**
* Parse the fulltext search parameter q
*
* @param string $qParam
* @param array $fullTextSearchColumns
* @return void
*/
protected function parseFullTextSearch($qParam, $fullTextSearchColumns)
{
if ($qParam == '') {
//Add where that will never be true
$this->query->whereRaw('0 = 1');
return;
}
$fulltextType = Config::get('apihandler.fulltext');
if ($fulltextType == 'native') {
//Use pdo's quote method to be protected against sql-injections.
//The usual placeholders unfortunately don't seem to work using AGAINST().
$qParam = $this->query->getConnection()->getPdo()->quote($qParam);
//Use native fulltext search
$this->query->whereRaw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE)');
//Add the * to the selects because of the score column
if (count($this->query->columns) == 0) {
$this->query->addSelect('*');
}
//Add the score column
$scoreColumn = Config::get('apihandler.fulltext_score_column');
$this->query->addSelect($this->query->raw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE) as `' . $scoreColumn . '`'));
} else {
$keywords = explode(' ', $qParam);
//Use default php implementation
$this->query->where(function ($query) use($fullTextSearchColumns, $keywords) {
foreach ($fullTextSearchColumns as $column) {
foreach ($keywords as $keyword) {
$query->orWhere($column, 'LIKE', '%' . $keyword . '%');
}
}
});
}
}
示例14: filterSearch
/**
* Метод фильтрует данные по словам
*
* @param string|int $search
* @param null $value word
* @param string $delimiter equal sign - '=', 'like' ...
* @param string $beforeValue First sign before value
* @param string $afterValue Last sign after value
*/
protected function filterSearch($search, $value = null, $delimiter = '=', $beforeValue = '', $afterValue = '')
{
if ($search) {
$value = trim($value);
$search = trim($search);
/** @var Model $model */
$model = $this->_query->getModel();
// поиск по словам
if (is_string($search) || is_numeric($search)) {
$this->_query->where(function ($query) use($model, $search, $value, $delimiter, $beforeValue, $afterValue) {
/** @var \Illuminate\Database\Eloquent\Builder $query */
$tableName = $model->getTable();
if ($value) {
if (Model::hasColumn($model, $search)) {
$query->orWhere($tableName . '.' . $search, $delimiter, $beforeValue . $value . $afterValue);
}
} else {
foreach (\Schema::getColumnListing($tableName) as $column) {
// из-за проблем поиска с кириллицей, костыль.
if (!preg_match("/[\\w]+/i", $search)) {
if (FilterEnum::hasFilterExecuteForCyrillicColumn($column)) {
continue;
}
}
if (Model::hasColumn($model, $column)) {
$query->orWhere($tableName . '.' . $column, 'like', '%' . $search . '%');
}
}
}
});
}
}
}
示例15: _wheres
/**
* like wheres function ,call by internal
* @param array $conds
* @return $this
*/
protected function _wheres($conds)
{
foreach ($conds as $field => $opAndVal) {
if (is_null($opAndVal)) {
$opAndVal = [null];
}
$opAndVal = (array) $opAndVal;
$op = strtolower(count($opAndVal) == 1 ? '=' : $opAndVal[0]);
$val = last($opAndVal);
$field = str_contains($field, '.') ? $field : $this->table . '.' . $field;
switch ($op) {
case 'in':
if (count($val) == 1) {
$this->operator->where($field, '=', $val[0]);
} else {
$this->operator->whereIn($field, $val);
}
break;
case 'between':
$this->operator->whereBetween($field, $val);
break;
case 'raw':
$this->operator->whereRaw($val);
break;
default:
$this->operator->where($field, $op, $val);
}
}
return $this;
}