本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::where方法的具体用法?PHP Builder::where怎么用?PHP Builder::where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeSearch
/**
* Apply filters in your QueryBuilder based in $fields
*
* @param \Illuminate\Database\Eloquent\Builder $queryBuilder
* @param array $fields
*
*/
public function scopeSearch(Builder $queryBuilder, $fields = [])
{
if (isset($this->searchable)) {
foreach ($fields as $field => $value) {
if (array_key_exists($field, $this->searchable)) {
switch ($this->searchable[$field]) {
// compare equals values
case 'MATCH':
$queryBuilder->where($field, $value);
break;
// compare like values
// compare like values
case 'LIKE':
array_map(function ($value) use($queryBuilder, $field) {
$queryBuilder->where($field, "LIKE", "%" . $value . "%");
}, explode(" ", $value));
break;
// compare between values
// compare between values
case 'BETWEEN':
if (is_array($value) && count($value) == 2) {
if (isset($value[0]) && !empty($value[0])) {
$queryBuilder->where($field, ">=", $value[0]);
}
if (isset($value[1]) && !empty($value[1])) {
$queryBuilder->where($field, "<=", $value[1]);
}
}
}
}
}
}
return $queryBuilder;
}
示例2: scopeEnabled
/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $id
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeEnabled($query, $id = null)
{
if ($id) {
$query->where('id', '=', $id);
}
return $query->where('disabled', '=', false);
}
示例3: 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));
});
}
示例4: processWhere
/**
* @param Builder $query
* @param $wheres
*/
private function processWhere(Builder $query, $wheres)
{
$self = $this;
foreach ($wheres as $where) {
/** @var WhereParameter $where */
$query->where(function (Builder $query) use($self, $where) {
if ($comparison = $where->getComparison()) {
$query->where($comparison->getSubject(), $comparison->getOperator(), $comparison->getValue());
}
foreach ($where->getChildren() as $child) {
if ($child instanceof AndConjunction) {
$query->where(function (Builder $query) use($self, $child) {
$this->processWhere($query, [$child->getSubject()]);
});
} elseif ($child instanceof OrConjunction) {
$query->orWhere(function (Builder $query) use($self, $child) {
$this->processWhere($query, [$child->getSubject()]);
});
} else {
throw new \InvalidArgumentException("Got an unknown conjunction");
}
}
});
}
}
示例5: like
/**
* Helper for "LIKE" filter
*
* @param String $column
* @param String $value
* @return Builder
*/
protected function like($column, $value)
{
if ($this->builder->getQuery()->getConnection()->getDriverName() == 'pgsql') {
return $this->builder->where($column, 'ILIKE', '%' . $value . '%');
}
return $this->builder->where($column, 'LIKE', '%' . $value . '%');
}
示例6: build
public function build(Builder $query)
{
if (is_array($this->pageId)) {
return $query->where('pages.id', 'not in', $this->pageId);
} else {
return $query->where('pages.id', '!=', $this->pageId);
}
}
示例7: searchWithTags
private function searchWithTags(Query $query, stdClass $argument)
{
return $query->where(function (Query $query) use($argument) {
$query->where('unit.name', $argument->operator, $argument->value)->orWhereHas('tags', function (Query $query) use($argument) {
$query->where('name', $argument->operator, $argument->value);
});
});
}
示例8: getByCredentials
/**
* @inheritdoc
*/
public function getByCredentials(array $credentials)
{
foreach ($credentials as $key => $value) {
if (strpos($key, 'password') === false) {
$this->queryBuilder->where($key, $value);
}
}
return $this->queryBuilder->first();
}
示例9: scopeActive
public function scopeActive(Builder $query)
{
$time = Date::floorToMinute();
return $query->where('disable', '')->where(function (Builder $query) use($time) {
return $query->where('start', '')->orWhere('start', '<=', $time);
})->where(function (Builder $query) use($time) {
return $query->where('stop', '')->orWhere('stop', '>', $time + 60);
});
}
示例10: modifyQuery
public function modifyQuery(Builder $query)
{
if ($this->get('user_id')) {
$query->where('user_id', $this->get('user_id'));
}
if ($this->get('role_id')) {
$query->where('role_id', $this->get('role_id'));
}
return $query;
}
示例11: scopeFindSimilarSlugs
/**
* Query scope for finding "similar" slugs, used to determine uniqueness.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $attribute
* @param array $config
* @param string $slug
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFindSimilarSlugs(Builder $query, Model $model, $attribute, $config, $slug)
{
$separator = $config['separator'];
foreach ($config['uniqueWhere'] as $param) {
if ($this->{$param}) {
$query->where($param, $this->{$param});
}
}
return $query->where($attribute, '=', $slug)->orWhere($attribute, 'LIKE', $slug . $separator . '%');
}
示例12: where
/**
* Add a where to the query
* @param string $field
* @param string $operator
* @param string $value
* @return $this
*/
public function where($field, $operator = null, $value = null)
{
// If there is only two arguments, the second one is the value
if (func_num_args() == 2) {
$value = $operator;
$operator = '=';
}
$this->builder = $this->builder->where($field, $operator, $value);
return $this;
}
示例13: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
*
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$strict = isset($model::$strictModeration) ? $model::$strictModeration : config('moderation.strict');
if ($strict) {
$builder->where($model->getQualifiedStatusColumn(), '=', Status::APPROVED);
} else {
$builder->where($model->getQualifiedStatusColumn(), '!=', Status::REJECTED);
}
$this->extend($builder);
}
示例14: putProductCategory
/**
* @param string $sku
* @param Request $request
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*
* @return \Illuminate\Http\RedirectResponse
*/
public function putProductCategory(string $sku, Request $request)
{
/** @var Product $product */
$product = $this->product->where('sku', '=', $sku)->firstOrFail();
$category = $this->category->findOrFail($request->get('category-id'));
$product->category()->associate($category);
$product->save();
$this->webUi->successMessage("Set category for `{$product->sku}` to `{$category->name}`.");
return $this->webUi->redirect('products.show', [$product->sku]);
}
示例15: applyLoggedInScope
/**
* Apply logged in scope.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Gitamin\Models\User $user
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function applyLoggedInScope(Builder $query, User $user)
{
$isPrivate = function ($query) use($user) {
$query->where('visibility_level', '=', self::VISIBILITY_PRIVATE)->where("{$this->tableName}.creator_id", '=', $user->id);
};
$whereVisible = function ($query) use($isPrivate) {
$query->whereIn('visibility_level', [self::VISIBILITY_PUBLIC, self::VISIBILITY_LOGGED_IN])->orWhere($isPrivate);
};
return $query->where($whereVisible);
}