本文整理汇总了PHP中Illuminate\Database\Query\Builder::orWhere方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::orWhere方法的具体用法?PHP Builder::orWhere怎么用?PHP Builder::orWhere使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::orWhere方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyOr
/**
* Call apply() within an "or" block
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder $query
*/
public function applyOr(\Illuminate\Database\Query\Builder $query)
{
$query->orWhere(function ($query) {
$this->apply($query);
});
return $query;
}
示例2: applyKeywordsFilter
/**
* {@inheritdoc}
*
* We will check for actual match rather than partial.
*/
public function applyKeywordsFilter(Builder $builder, array $keywords)
{
foreach ($keywords as $keyword) {
if (is_numeric($keyword)) {
$builder->orWhere($this->id, '=', $keyword);
}
}
}
示例3: process
protected function process()
{
$this->method = 'GET';
//database save
switch ($this->action) {
case "search":
// prepare the WHERE clause
foreach ($this->fields as $field) {
$field->getValue();
//$field->getNewValue();
//die( '..'.$field->value);
if ($field->value != "") {
if (strpos($field->name, "_copy") > 0) {
$name = substr($field->db_name, 0, strpos($field->db_name, "_copy"));
} else {
$name = $field->db_name;
}
$value = $field->value;
switch ($field->clause) {
case "like":
$this->query = $this->query->where($name, 'LIKE', '%' . $value . '%');
break;
case "orlike":
$this->query = $this->query->orWhere($name, 'LIKE', '%' . $value . '%');
break;
case "where":
$this->query = $this->query->where($name, $field->operator, $value);
break;
case "orwhere":
$this->query = $this->query->orWhere($name, $field->operator, $value);
break;
}
}
}
case "reset":
$this->process_status = "show";
return true;
break;
default:
return false;
}
}
示例4: search
/**
* @param $search
* @param $columns
* @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
*/
protected function search($search, $columns, $query)
{
if ($search) {
$query->where(function ($query) use($search, $columns) {
foreach ($columns as $column) {
$query->orWhere($column, 'LIKE', "%{$search}%");
}
});
}
return $query;
}
示例5: 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());
}
});
});
}
示例6: scopeForModel
/**
* Constrain a query to an permission for a specific model.
*
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
* @param \Illuminate\Database\Eloquent\Model|string $model
* @param bool $strict
* @return void
*/
public function scopeForModel($query, $model, $strict = false)
{
$model = is_string($model) ? new $model() : $model;
$query->where(function ($query) use($model, $strict) {
$query->where('entity_type', $model->getMorphClass());
$query->where(function ($query) use($model, $strict) {
// If the model does not exist, we want to search for blanket permissions
// that cover all instances of this model. If it does exist, we only
// want to find blanket permissions if we're not using strict mode.
if (!$model->exists || !$strict) {
$query->whereNull('entity_id');
}
if ($model->exists) {
$query->orWhere('entity_id', $model->getKey());
}
});
});
}
示例7: addFilterQuery
/**
* Add global filter to query builder
* @param \Illuminate\Database\Query\Builder $query object is by reference
*/
protected function addFilterQuery($query)
{
if (isset($this->filter)) {
$likable = null;
$table = $this->attributes('table');
$map = $this->attributes('map');
foreach ($map as $property => $options) {
if (isset($options['column']) && isset($options['likable']) && $options['likable'] == true) {
$likable[] = $table . "." . $options['column'];
}
}
if (isset($likable)) {
$query->where(function ($query) use($likable) {
foreach ($likable as $like) {
$query->orWhere($this->map($like), 'like', "%{$this->filter}%");
}
});
} else {
// No columns are likable, just use primary with = (not like)
$primary = $this->attributes('primary');
if (isset($primary)) {
$query->where($primary, $this->filter);
}
}
}
}
示例8: filterQueryKanji
/**
* @param string $kanji
* @param \Illuminate\Database\Query\Builder $q
* @param string $colName
*/
public static function filterQueryKanji($kanji, $q, $colName)
{
if (isset($kanji)) {
$decoded_kanji = rawurldecode($kanji);
if ($kanji !== '_' && $kanji !== '-') {
$q->orWhere($colName, 'like', '%' . $decoded_kanji . '%');
}
}
}
示例9: orWhere
/**
* Add an "or where" clause to the query.
*
* @param string $column
* @param string $operator
* @param mixed $value
* @return \Illuminate\Database\Query\Builder|static
* @static
*/
public static function orWhere($column, $operator = null, $value = null)
{
return \Illuminate\Database\Query\Builder::orWhere($column, $operator, $value);
}
示例10: isReservedButExpired
/**
* Modify the query to check for jobs that are reserved but have expired.
*
* @param \Illuminate\Database\Query\Builder $query
* @return void
*/
protected function isReservedButExpired($query)
{
$expiration = Carbon::now()->subSeconds($this->expire)->getTimestamp();
$query->orWhere(function ($query) use($expiration) {
$query->where('reserved', 1);
$query->where('reserved_at', '<=', $expiration);
});
}
示例11: searches
/**
* 주어진 query에 like 검색 조건을 추가한다.
*
* @param Builder $query 검색조건을 적용할 query
* @param mixed $searches 검색할 조건
*
* @return Builder
*/
protected function searches($query, $searches)
{
foreach ($searches as $field => $value) {
$fields = explode(',', $field);
$query->where(array_shift($fields), 'like', '%' . $value . '%');
foreach ($fields as $f) {
$query->orWhere($f, 'like', '%' . $value . '%');
}
}
return $query;
}
示例12: applySearch
/**
* Apply search to the query.
*
* @param Builder $query
*/
protected function applySearch(Builder $query)
{
$search = Input::get('search.value');
if (is_null($search)) {
return;
}
$query->where(function ($query) use($search) {
$columns = $this->columns();
foreach ($columns as $column) {
if ($column instanceof String) {
$name = $column->name();
if ($this->repository->hasColumn($name)) {
$query->orWhere($name, 'like', '%' . $search . '%');
}
}
}
});
}
示例13: orWhere
/**
* @param \Illuminate\Database\Query\Builder $query
* @param string $field
* @param array $rule
*/
protected function orWhere($query, $field, $rule)
{
$configs = $this->configs($rule);
$value = trim($this->data->get($configs->get('get', $field), ''));
if ($value == '') {
return;
}
$condition = $configs->get('options');
$condition = array_shift($condition);
if (in_array($condition, ['=', '<', '>', '<>', '<=', '>='])) {
$query->orWhere($field, $condition, $value);
} elseif ($condition == '%like%') {
$query->orWhere($field, 'like', "%{$value}%");
} elseif ($condition == 'like%') {
$query->orWhere($field, 'like', "{$value}%");
} elseif ($condition == '%like') {
$query->orWhere($field, 'like', "%{$value}");
} elseif ($condition == 'like') {
$query->orWhere($field, 'like', "{$value}");
}
}
示例14: buildWildcardQueryFilterWithKeyword
/**
* Build wildcard query filter by keyword.
*
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
* @param string $field
* @param array $keyword
* @param string $group
*
* @return void
*/
protected function buildWildcardQueryFilterWithKeyword($query, $field, array $keyword = [], $group = 'where')
{
$callback = function ($query) use($field, $keyword) {
foreach ($keyword as $key) {
$query->orWhere($field, 'LIKE', $key);
}
};
$query->{$group}($callback);
}
示例15: process
protected function process()
{
$this->method = 'GET';
//database save
switch ($this->action) {
case "search":
// prepare the WHERE clause
foreach ($this->fields as $field) {
$field->getValue();
$field->getNewValue();
$value = $field->new_value;
//query scope
$query_scope = $field->query_scope;
$query_scope_params = $field->query_scope_params;
if ($query_scope) {
if (is_a($query_scope, '\\Closure')) {
array_unshift($query_scope_params, $value);
array_unshift($query_scope_params, $this->query);
$this->query = call_user_func_array($query_scope, $query_scope_params);
} elseif (isset($this->model) && method_exists($this->model, "scope" . $query_scope)) {
$query_scope = "scope" . $query_scope;
array_unshift($query_scope_params, $value);
array_unshift($query_scope_params, $this->query);
$this->query = call_user_func_array([$this->model, $query_scope], $query_scope_params);
}
continue;
}
//detect if where should be deep (on relation)
$deep_where = false;
if (isset($this->model) && $field->relation != null) {
$rel_type = get_class($field->relation);
if (is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\HasOne') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\HasMany') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsTo') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany')) {
if (is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsTo') and in_array($field->type, array('select', 'radiogroup', 'autocomplete'))) {
$deep_where = false;
} else {
$deep_where = true;
}
}
}
if ($value != "" or is_array($value) and count($value)) {
if (strpos($field->name, "_copy") > 0) {
$name = substr($field->db_name, 0, strpos($field->db_name, "_copy"));
} else {
$name = $field->db_name;
}
//$value = $field->value;
if ($deep_where) {
//exception for multiple value fields on BelongsToMany
if (is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany') || is_a($field->relation, 'Illuminate\\Database\\Eloquent\\Relations\\BelongsTo') and in_array($field->type, array('tags', 'checks', 'multiselect'))) {
$values = explode($field->serialization_sep, $value);
if ($field->clause == 'wherein') {
$this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $values) {
$q->whereIn($field->rel_fq_key, $values);
});
}
if ($field->clause == 'where') {
foreach ($values as $v) {
$this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $v) {
$q->where($field->rel_fq_key, '=', $v);
});
}
}
continue;
}
switch ($field->clause) {
case "like":
$this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $value) {
$q->where($field->rel_field, 'LIKE', '%' . $value . '%');
});
break;
case "orlike":
$this->query = $this->query->orWhereHas($field->rel_name, function ($q) use($field, $value) {
$q->where($field->rel_field, 'LIKE', '%' . $value . '%');
});
break;
case "where":
$this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $value) {
$q->where($field->rel_field, $field->operator, $value);
});
break;
case "orwhere":
$this->query = $this->query->orWhereHas($field->rel_name, function ($q) use($field, $value) {
$q->where($field->rel_field, $field->operator, $value);
});
break;
case "wherebetween":
$values = explode($field->serialization_sep, $value);
$this->query = $this->query->whereHas($field->rel_name, function ($q) use($field, $values) {
if ($values[0] != '' and $values[1] == '') {
$q->where($field->rel_field, ">=", $values[0]);
} elseif ($values[0] == '' and $values[1] != '') {
$q->where($field->rel_field, "<=", $values[1]);
} elseif ($values[0] != '' and $values[1] != '') {
//we avoid "whereBetween" because a bug in laravel 4.1
$q->where(function ($query) use($field, $values) {
return $query->where($field->rel_field, ">=", $values[0])->where($field->rel_field, "<=", $values[1]);
});
}
});
break;
//.........这里部分代码省略.........