本文整理汇总了PHP中Builder::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::where方法的具体用法?PHP Builder::where怎么用?PHP Builder::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scopeSearch
/**
* Search scope
*
* @param Builder $query
* @param string $keywords
* @return Builder
*/
public function scopeSearch($query, $keywords)
{
//Return search results
return $query->where(function ($query) use($keywords) {
$query->where('first_name', 'like', $keywords . '%')->orWhere('last_name', 'like', $keywords . '%')->orWhereRaw('CONCAT(first_name, \' \',last_name) like \'' . $keywords . '%\'');
});
}
示例2: scopePublished
/**
* @param Builder $query
*
* @return mixed
*/
public function scopePublished($query)
{
return $query->where(function ($query) {
$query->where(function ($query) {
$query->where('published_at', '<=', Carbon::now())->orWhere('published_at', null);
});
$query->where(function ($query) {
$query->where('concealed_at', '>=', Carbon::now())->orWhere('concealed_at', null);
});
});
}
示例3: getBuilder
/**
* Resolves all the ScopeInterface items into the current Builder.
* @return \Illuminate\Database\Query\Builder $query
*/
public function getBuilder()
{
$this->query = clone $this->baseQuery;
//apply all direct scopes to the query.
$this->directScopes->each(function ($scope) {
$scope_method = 'apply';
$this->query = $scope->{$scope_method}($this->query);
});
//chain all required scopes in "AND" blocks
$this->requiredScopes->each(function ($scope) {
$scope_method = 'applyAnd';
$this->query = $scope->{$scope_method}($this->query);
});
//chain all optional scopes using "OR", nested within a single "AND" block.
if ($this->optionalScopes->count()) {
$this->query->where(function ($query) {
$this->optionalScopes->each(function ($scope) use($query) {
$scope_method = 'applyOr';
return $scope->{$scope_method}($query);
});
});
}
collect([])->merge($this->directScopes)->merge($this->requiredScopes)->merge($this->optionalScopes)->each(function ($scope) {
$this->parseScope($scope);
});
return $this->query;
}
示例4: doColumnSearch
/**
* Perform column search
*
* @return void
*/
public function doColumnSearch()
{
$input = $this->input;
$columns = $input['columns'];
// if older version, set the column name to query's fields
// or if new version but does not use mData support
if (!$this->new_version or !$this->mDataSupport and $this->new_version) {
for ($i = 0; $i < count($columns); $i++) {
if (!isset($this->columns[$i])) {
continue;
}
$columns[$i]['name'] = $this->columns[$i];
if (stripos($columns[$i]['name'], ' AS ') !== false or $columns[$i]['name'] instanceof Expression) {
$columns[$i]['name'] = '';
$columns[$i]['searchable'] = false;
$columns[$i]['orderable'] = false;
}
}
}
for ($i = 0, $c = count($columns); $i < $c; $i++) {
if ($columns[$i]['searchable'] == "true" and !empty($columns[$i]['search']['value']) and !empty($columns[$i]['name'])) {
$column = $columns[$i]['name'];
$keyword = $this->setupKeyword($columns[$i]['search']['value']);
// wrap column possibly allow reserved words to be used as column
$column = $this->wrapColumn($column);
if ($this->isCaseInsensitive()) {
$this->query->whereRaw('LOWER(' . $column . ') LIKE ?', [strtolower($keyword)]);
} else {
$col = strstr($column, '(') ? $this->connection->raw($column) : $column;
$this->query->where($col, 'LIKE', $keyword);
}
}
}
}
示例5: options
/**
* Set query options and params
* @param array $options
* @return Builder
*/
public function options($options = array())
{
// Get order options
$orderBy = array_get($options, 'order_by', 'created_at');
$order = array_get($options, 'order', 'desc');
// Run order
if ($orderBy == 'rand') {
$this->query->orderBy(DB::raw('RAND()'), $order);
} else {
$this->query->orderBy($orderBy, $order);
}
// Also the limit
if ($limit = array_get($options, 'limit')) {
$this->defaultLimit = (int) $limit;
}
if (is_array($options)) {
foreach ($options as $key => $value) {
if (!in_array($key, array('limit', 'order_by'))) {
if (is_array($value)) {
$this->query->where($key, $value[0], $value[1]);
} else {
$this->query->where($key, $value);
}
}
}
}
return $this->query;
}
示例6: scopeAreFriends
/**
* Query scope that returns only the friendships of two users
*
* @param Builder $query The query builder object
* @param int $friendOneId The ID of the first user
* @param int $friendTwoId The ID of the second user
* @return Builder
*/
public function scopeAreFriends($query, $friendOneId, $friendTwoId)
{
return $query->where(function ($query) use($friendOneId, $friendTwoId) {
$query->whereSenderId($friendOneId)->whereReceiverId($friendTwoId);
})->orWhere(function ($query) use($friendOneId, $friendTwoId) {
$query->whereReceiverId($friendOneId)->whereSenderId($friendTwoId);
});
}
示例7: scopeFriendsOf
/**
* Query scope that returns the friendships of a user
*
* @param Builder $query The query builder object
* @param int $userId The ID of the user
* @param boolean $confirmed Only show confirmed friendships? Default = true
* @return Builder
*/
public function scopeFriendsOf($query, $userId, $confirmed = true)
{
if ($confirmed) {
$query->whereConfirmed(1);
}
return $query->where(function ($query) use($userId) {
$query->whereSenderId($userId)->orWhere('receiver_id', $userId);
});
}
示例8: dtPerformGlobalFilter
/**
* Perform filter for global
*
* @param array $columns
* @param string $search
* @return self
*/
public function dtPerformGlobalFilter($columns, $search = '')
{
$this->dtModel = $this->dtModel->where(function ($query) use($columns, $search) {
foreach ($columns as $column) {
if (filter_var($column['searchable'], FILTER_VALIDATE_BOOLEAN) && !in_array($column['name'], $this->dtUnsearchable)) {
$query->orWhere(DB::raw($column['name']), 'LIKE', '%' . $search['value'] . '%');
}
}
});
return $this;
}
示例9: scopeFindByUuid
/**
* Method returns models geted by uuid
* @param Builder $query
* @param array|tring $uuid uuid or list of uuids
* @return Collection|Model Single model or collection of models
*/
public function scopeFindByUuid($query, $uuid)
{
if (!is_array($uuid)) {
if (!Uuid::isValid($uuid)) {
throw (new ModelNotFoundException())->setModel(get_class($this));
}
return $query->where('uuid', $uuid)->first();
} elseif (is_array($uuid)) {
array_map(function ($element) {
if (!Uuid::isValid($element)) {
throw (new ModelNotFoundException())->setModel(get_class($this));
}
}, $uuid);
return $query->whereIn('uuid', $uuid)->get();
}
}
示例10: doColumnSearch
/**
* Perform column search
*
* @param array $columns
* @return void
*/
public function doColumnSearch(array $columns)
{
for ($i = 0, $c = count($columns); $i < $c; $i++) {
if ($columns[$i]['searchable'] == "true" and !empty($columns[$i]['search']['value']) and !empty($columns[$i]['name'])) {
$column = $columns[$i]['name'];
$keyword = $this->setupKeyword($columns[$i]['search']['value']);
// wrap column possibly allow reserved words to be used as column
$column = $this->wrapColumn($column);
if ($this->isCaseInsensitive()) {
$this->query->whereRaw('LOWER(' . $column . ') LIKE ?', [strtolower($keyword)]);
} else {
$col = strstr($column, '(') ? $this->connection->raw($column) : $column;
$this->query->where($col, 'LIKE', $keyword);
}
}
}
}
示例11: scopeIsAccessible
/**
* Select only those forums the user has access to.
* WARNING: Creates JOINs with the forum_threads and the forums table.
*
* @param Builder $query The Eloquent Builder object
* @param User $user User model or null if it's the current client
* @return Builder
*/
public function scopeIsAccessible($query, $user = null)
{
$query->select('forum_posts.*')->join('forum_threads', 'forum_posts.thread_id', '=', 'forum_threads.id')->join('forums', 'forum_threads.forum_id', '=', 'forums.id');
if (!$user) {
$user = user();
}
if ($user) {
$internal = $user->hasAccess('internal');
$teamIds = DB::table('team_user')->whereUserId($user->id)->lists('team_id');
$teamIds[] = -1;
// Add -1 as team ID so the SQL statements (`team_id` in (...)) always has valid syntax
return $query->where('internal', '<=', $internal)->where(function ($query) use($teamIds) {
$query->whereNull('team_id')->orWhereIn('team_id', $teamIds);
});
} else {
return $query->whereInternal(0)->whereNull('team_id');
}
}
示例12: scopeTransWhere
/**
* Applies a translatable index to a basic query. This scope will join the index
* table and cannot be executed more than once.
* @param Builder $query
* @param string $index
* @param string $value
* @param string $locale
* @return Builder
*/
public function scopeTransWhere($query, $index, $value, $locale = null)
{
if (!$locale) {
$locale = $this->translatableContext;
}
$query->select($this->model->getTable() . '.*');
$query->where(function ($q) use($index, $value) {
$q->where($this->model->getTable() . '.' . $index, $value);
$q->orWhere(function ($q) use($index, $value) {
$q->where('rainlab_translate_indexes.item', $index)->where('rainlab_translate_indexes.value', $value);
});
});
// This join will crap out if this scope executes twice, it is a known issue.
// It should check if the join exists before applying it, this mechanism was
// not found in Laravel. So options are block joins entirely or allow once.
$query->leftJoin('rainlab_translate_indexes', function ($join) use($locale) {
$join->on(Db::raw(DbDongle::cast($this->model->getQualifiedKeyName(), 'TEXT')), '=', 'rainlab_translate_indexes.model_id')->where('rainlab_translate_indexes.model_type', '=', get_class($this->model))->where('rainlab_translate_indexes.locale', '=', $locale);
});
return $query;
}
示例13: scopeSimpleSearch
/**
* A scope filter to only show items which have a given string in one
* or more of it's columns, defined by the searchables property
*
* @param Builder $query Original query
* @param string $search_term term to search for
* @param boolean $loose whether to form exact matches only
* @return Builder Filtered query
*/
public function scopeSimpleSearch($query, $search_term, $loose = true)
{
if ($loose) {
$search_term = "%{$search_term}%";
}
return $query->where(function ($sub_query) use($search_term) {
$searchables = $this->getSearchables();
if (count($searchables) === 0) {
throw new Exception("Attempting to search Model with no fields to search by");
} elseif (count($searchables) === 1) {
return $sub_query->where($searchables[0], 'LIKE', $search_term);
} else {
// Pop the first item to initiate a where set
$first = array_shift($searchables);
$sub_query->where($first, 'LIKE', $search_term);
// Then loop through the remainder to add them as 'or where' participants
foreach ($searchables as $column_name) {
$sub_query->orWhere($column_name, 'LIKE', $search_term);
}
}
return $sub_query;
});
}
示例14: scopePatchId
public function scopePatchId(Builder $query, $patch_id)
{
return $query->where('patch_id', $patch_id);
}
示例15: scopeInRoot
/**
* Root scope
*
* @param Builder $query
* @return Builder $query
*/
public function scopeInRoot($query)
{
return $query->where($this->getContainerKeyName(), null);
}