本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::whereRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::whereRaw方法的具体用法?PHP Builder::whereRaw怎么用?PHP Builder::whereRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::whereRaw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
if ($this->enabled === false) {
return;
}
foreach ($this->getModelTenants($model) as $tenantColumn => $tenantId) {
$builder->whereRaw($model->getTenantWhereClause($tenantColumn, $tenantId));
}
}
示例2: scopeWherePgJsonbKeysExist
/**
* Check if jsonb field has all or any of the keys/elements specified in $keys array
* @param Builder $query
* @param string $column
* @param array $keys
* @param string $has all|any
* @return Builder
*/
public function scopeWherePgJsonbKeysExist(Builder $query, $column, array $keys, $has = 'all')
{
$mark = '&';
if ($has === 'any') {
$mark = '|';
}
$keys = Helper::phpArrayToPostgresArray($keys);
$column = Helper::nestedJsonColumn($column);
return $query->whereRaw("{$column} \\?{$mark} ?", [$keys]);
}
示例3: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param Builder|\Illuminate\Database\Query\Builder $builder
* @param Model|\Illuminate\Database\Query\Model $model
*
* @return void
*/
public function apply(Builder $builder, Model $model)
{
if (!$this->enabled) {
return;
}
// Use whereRaw instead of where to avoid issues with bindings when removing
foreach ($this->getModelTenants($model) as $tenantColumn => $tenantId) {
$builder->whereRaw($model->getTenantWhereClause($tenantColumn, $tenantId));
}
}
示例4: createWhere
/**
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
*/
protected function createWhere(EloquentBuilder $builder, Eloquent $model)
{
if ($model->getOnlyTranslated() && $model->shouldFallback()) {
$key = $model->getForeignKey();
$primary = "{$this->i18nTable}.{$key}";
$fallback = "{$this->i18nTable}_fallback.{$key}";
$ifNull = $builder->getQuery()->compileIfNull($primary, $fallback);
$builder->whereRaw("{$ifNull} is not null");
}
}
示例5: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @throws TenantNotSetError
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$this->refreshTenant();
if ($this->disabled) {
return;
}
if ($this->tenant_id === null) {
throw new TenantNotSetError();
}
$builder->whereRaw("{$builder->getQuery()->from}.{$this->tenant_column} = {$this->tenant_id}");
}
示例6: find
/**
* @param User $actor
* @param Builder $query
*/
public function find(User $actor, Builder $query)
{
if ($actor->cannot('viewDiscussions')) {
$query->whereRaw('FALSE');
} elseif (!$actor->hasPermission('discussion.hide')) {
$query->where(function ($query) use($actor) {
$query->whereNull('discussions.hide_time')->where('comments_count', '>', 0)->orWhere('start_user_id', $actor->id);
$this->events->fire(new ScopeHiddenDiscussionVisibility($query, $actor, 'discussion.hide'));
});
}
}
示例7: scopeWhereVisibleTo
/**
* Scope a query to only include records that are visible to a user.
*
* @param Builder $query
* @param User $actor
*/
public function scopeWhereVisibleTo(Builder $query, User $actor)
{
if (!app('flarum.forum')->can($actor, 'view')) {
if ($this instanceof User) {
$query->where('id', $actor->id);
} else {
$query->whereRaw('FALSE');
}
} else {
event(new ScopeModelVisibility($this, $query, $actor));
}
}
示例8: getRelationQuery
/**
* @param EloquentBuilder $query
* @param EloquentBuilder $parent
* @param array $columns
*
* @return mixed
*/
public function getRelationQuery(EloquentBuilder $query, EloquentBuilder $parent, $columns = ['*'])
{
$query->select($columns);
$table = $query->getModel()->getTable();
$query->from($table . ' as ' . ($hash = $this->getRelationCountHash()));
$grammar = $query->getQuery()->getGrammar();
$table = $grammar->wrapTable($table);
$hash = $grammar->wrapTable($hash);
$lft = $grammar->wrap($this->parent->getLftName());
$rgt = $grammar->wrap($this->parent->getRgtName());
return $query->whereRaw("{$hash}.{$lft} between {$table}.{$lft} + 1 and {$table}.{$rgt}");
}
示例9: apply
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
*
* @throws Exceptions\TenantIdNotSetException
* @return void
*/
public function apply(Builder $builder)
{
if (is_null(self::getTenantId())) {
if (self::$enabled) {
throw new TenantIdNotSetException();
}
return;
}
/** @var \Illuminate\Database\Eloquent\Model|ScopedByTenant $model */
$model = $builder->getModel();
// Use whereRaw instead of where to avoid issues with bindings when removing
$builder->whereRaw($model->getTenantWhereClause());
}
示例10: apply
public function apply(Builder $builder, Model $model)
{
if (!$this->isEnabled($model)) {
return;
}
$traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($traces as $trace) {
// Find the first non-vendor-dir file in the backtrace
if (isset($trace['file']) && !str_contains($trace['file'], DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR)) {
$file = '"query.file" <> "' . $trace['file'] . '"';
$line = '"query.line" <> "' . $trace['line'] . '"';
return $builder->whereRaw($file)->whereRaw($line);
}
}
}
示例11: apply
/**
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
if (!Auth::guest() && Auth::user()->hasCountryRole()) {
$country = Auth::user()->country;
if ($builder->getModel()->getTable() == "activity_logs") {
$builder->whereHas('contract', function ($q) use($country) {
$q->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
});
} elseif ($builder->getModel()->getTable() == "contract_annotations") {
$builder->whereHas('contract', function ($q) use($country) {
$q->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
});
} else {
$builder->whereRaw("contracts.metadata->'country'->>'code' in (?)", $country);
}
}
}
示例12: apply
/**
* Apply the scope to a given Eloquent query builder.
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $builder
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->whereRaw("level = {$this->level}");
}
示例13: scopeInIntegerSlot
/**
* Only retrieve files whose slots are integers.
*
* @param Builder $query
* @return Builder
*/
public function scopeInIntegerSlot(Builder $query)
{
return $query->whereRaw(sprintf('%s.slot REGEXP \'^[[:digit:]]+$\'', $query->getQuery()->from));
}
示例14: find
/**
* @param User $actor
* @param Builder $query
*/
public function find(User $actor, Builder $query)
{
if ($actor->cannot('viewDiscussions')) {
$query->whereRaw('FALSE');
}
}
示例15: scopeWherePgArrayOverlap
/**
* Where database array $column has any of the elements in $value
* @param Builder $query
* @param string $column
* @param mixed $value
* @return Builder
*/
public function scopeWherePgArrayOverlap(Builder $query, $column, $value)
{
$value = self::mutateToPgArray((array) $value);
return $query->whereRaw("{$column} && ?", [$value]);
}