本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::addSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::addSelect方法的具体用法?PHP Builder::addSelect怎么用?PHP Builder::addSelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::addSelect方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkQuerySelects
protected function checkQuerySelects()
{
$selects = $this->query->getQuery()->columns;
$tableSelect = $this->model->getTable() . '.*';
if (empty($selects) || !in_array($tableSelect, $selects)) {
$this->query->addSelect($tableSelect);
}
}
示例2: getQuery
/**
* Return the query.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getQuery()
{
// If report is detailed, add all columns of modelGridQueries used by the gridQuery.
// If report is summary, and method summaryGroupBy() is called, the columns are added
// starting from the groupByKey which is a column of an modelGridQuery
if ($this->isDetailed) {
$this->query->addSelect($this->gridQuery->makeSelect($this->gridQuery->columnsToAddSelect()));
}
return $this->query;
}
示例3: select
/**
* @param Builder $query
*
* @return void
*/
public function select(Builder $query)
{
if (!is_null($select = $this->getRule()->getField()->getSelectField())) {
if ($select instanceof Builder) {
$query->selectSub($select->toSql(), $this->getRule()->getField()->getQueryField());
} else {
$query->addSelect($select);
}
}
}
示例4: filter
/**
* Filter a query by the value of a
* field using this field type.
*
* @param Builder $query
* @param FilterInterface $filter
*/
public function filter(Builder $query, FilterInterface $filter)
{
$stream = $filter->getStream();
$assignment = $stream->getAssignment($filter->getField());
$column = $this->fieldType->getColumnName();
$translations = $stream->getEntryTranslationsTableName();
if ($assignment->isTranslatable()) {
if ($query instanceof EloquentQueryBuilder && !$query->hasJoin($translations)) {
$query->leftJoin($stream->getEntryTranslationsTableName(), $stream->getEntryTableName() . '.id', '=', $stream->getEntryTranslationsTableName() . '.entry_id');
}
$query->addSelect($translations . '.locale');
$query->addSelect($translations . '.' . $column);
$query->{$this->where()}(function (Builder $query) use($stream, $filter, $column) {
$query->where($stream->getEntryTranslationsTableName() . '.locale', config('app.locale'));
$query->where($stream->getEntryTranslationsTableName() . '.' . $column, 'LIKE', "%" . $filter->getValue() . "%");
});
} else {
$query->{$this->where()}(function (Builder $query) use($stream, $filter, $column) {
$query->where($stream->getEntryTableName() . '.' . $column, 'LIKE', "%" . $filter->getValue() . "%");
});
}
}
示例5: 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)
{
if (isset($model['calculated_columns'])) {
$builder->addSelect('*');
foreach ($model['calculated_columns'] as $column => $query) {
if (str_contains($query, ':user_id')) {
$query = auth() && auth()->user() ? str_replace(':user_id', auth()->user()->id, $query) : 'false';
}
$builder->selectSub($query, $column);
}
}
return $builder;
}
示例6: filterScopes
/**
* Очень простая фильтрация скоупов.
*
* Если необходимо отфильтровать скоупы по id чему либо, обязательно нужно создать scope следующего вида.<br>
* Пример:
* * Ссылка для фильтрации - `catalog_id=*`
* * Метод - `public function scopeCatalogId($int) {}`
*
* @return \Illuminate\Support\Collection
*/
protected function filterScopes()
{
if (count($this->_request) > 0) {
foreach ($this->_request as $scope => $value) {
if (!empty($value)) {
//checked scope method for model
if (method_exists($this->_query->getModel(), 'scope' . camel_case($scope))) {
$this->_query->{camel_case($scope)}($value);
} else {
$values = explode(',', $value);
if (count($values) > 1) {
$this->filterSearch($scope, $values[0], '>');
$this->filterSearch($scope, $values[1], '<');
} else {
$this->filterSearch($scope, $value, 'like', '%', '%');
}
}
}
}
$this->_query->addSelect($this->_query->getModel()->getTable() . '.*');
}
return $this->_request;
}
示例7: execute
public function execute(Builder $query)
{
return $query->addSelect(DB::raw("(((match(search_texts.title) against ('{$this->text}')) * 100) + ((match(search_texts.meta) against ('{$this->text}')) * 20) + ((match(search_texts.standfirst) against ('{$this->text}')) * 10) + match(search_texts.text) against ('{$this->text}')) as rel"))->join('search_texts', 'pages.id', '=', 'search_texts.page_id')->where('search_texts.embargoed_until', '<=', time())->orderBy('rel', 'desc');
}
示例8: addSelectsToQuery
/**
* Puts all the select clauses to the main query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $selects
*/
protected function addSelectsToQuery(Builder $query, array $selects)
{
$selects = new Expression(implode(' + ', $selects) . ' as relevance');
$query->addSelect($selects);
}
示例9: querySelectColumn
/**
* @param Builder $query
* @param DocumentInterface $document
*/
public function querySelectColumn(Builder $query, DocumentInterface $document)
{
$query->addSelect($this->getDBKey());
}
示例10: apply
/**
* @param Builder $table
*
* @return Builder
*/
public function apply(Builder $table)
{
return $table->addSelect($this->getColumnsToSelect());
}
示例11: build
public function build(Builder $query)
{
return $query->addSelect(DB::raw('count(pages_tags.tag_id) as tag_count'))->join('pages_tags', 'pages.id', '=', 'pages_tags.page_id')->whereIn('tag_id', $this->tagIds)->where('pages.id', '!=', $this->page->getId())->orderBy('tag_count', 'desc')->orderBy(DB::raw('rand()'))->groupBy('pages.id');
}