本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::select方法的具体用法?PHP Builder::select怎么用?PHP Builder::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: relatedEventsOutcome
/**
* @param EloquentBuilder $query
*/
private function relatedEventsOutcome(EloquentBuilder $query)
{
$query->orWhere(function (EloquentBuilder $query) {
$query->where('entity_type', 'App\\Outcome')->whereIn('entity_id', function (QueryBuilder $query) {
$query->select('id')->from('outcomes')->whereIn('envelope_id', function (QueryBuilder $query) {
$query->select('id')->from('envelopes')->where('account_id', $this->id);
});
});
});
}
示例2: apply
/**
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
$builder->join('post_translations', function ($join) {
$join->on('posts.id', '=', 'post_translations.post_id')->where('post_translations.locale', '=', app()->getLocale())->where('post_translations.publish_at', '<', Carbon::now()->format('Y-m-d H:i:s'));
});
$builder->select(['posts.*']);
}
示例3: find
/**
* @param User $actor
* @param Builder $query
*/
public function find(User $actor, Builder $query)
{
// Hide discussions which have tags that the user is not allowed to see.
$query->whereNotExists(function ($query) use($actor) {
return $query->select(new Expression(1))->from('discussions_tags')->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'))->where('discussions.id', new Expression('discussion_id'));
});
}
示例4: scopeWithRelatedTranslations
public function scopeWithRelatedTranslations(Builder $query, $relation, $andFields = [])
{
$model = $relation->getRelated();
$withFallback = $model->usePublicFallback();
$translatedAttributes = array_merge($model->translatedAttributes, $andFields);
$translatedAttributes = array_map(function ($attribute) use($model) {
return $model->getPublicTranslationsTable() . '.' . $attribute . ' AS ' . $model->getPublicTranslationsTable() . '_' . $attribute;
}, $translatedAttributes);
$query->withTranslations();
$translatedAttributes = array_merge((array) $query->getQuery()->columns, $translatedAttributes);
$query->select($translatedAttributes)->leftJoin($model->getPublicTranslationsTable(), $model->getPublicTranslationsTable() . '.' . $model->getRelationKey(), '=', $relation->getQualifiedForeignKey())->where(function ($query) use($model, $withFallback) {
$query->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->publicLocale());
if ($withFallback) {
$query->orWhere(function (Builder $q) use($model) {
$q->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->getPublicFallbackLocale($model->publicLocale()))->whereNotIn($model->getPublicTranslationsTable() . '.' . $model->getRelationKey(), function (QueryBuilder $q) use($model) {
$q->select($model->getPublicTranslationsTable() . '.' . $model->getRelationKey())->from($model->getPublicTranslationsTable())->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->publicLocale());
});
})->orWhere(function (Builder $q) use($model) {
$q->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->getPublicFallbackLocale())->whereNotIn($model->getPublicTranslationsTable() . '.' . $model->getRelationKey(), function (QueryBuilder $q) use($model) {
$q->select($model->getPublicTranslationsTable() . '.' . $model->getRelationKey())->from($model->getPublicTranslationsTable())->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->getPublicFallbackLocale($model->publicLocale()))->orWhere($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->publicLocale());
});
});
}
});
}
示例5: apply
/**
* Apply the scope to a given Eloquent query builder.
* @param Builder $builder
* @param Model $model
*/
public function apply(Builder $builder, Model $model)
{
$builder->join('product_translations', function ($join) {
$join->on('products.id', '=', 'product_translations.product_id')->where('product_translations.locale', '=', app()->getLocale())->where('product_translations.published', '=', 1);
});
$builder->select(['products.*']);
}
示例6: find
/**
* @param $id
* @param bool $orFail
* @return Model|null
*
* method attempts to find record with given id
*/
public function find($id, $orFail = false)
{
if ($this->cache) {
$this->cacheKey = ($this->onlyVisible ? '-' : '+') . ($this->onlyAuthored ? '-' : '+') . "{$this->baseName}.find[{$id}]";
if ($cache = Cache::get($this->cacheKey)) {
$this->clearFilters();
return $cache === 'null' ? null : $cache;
}
}
$this->model = new $this->modelClass();
$table = $this->model->getTable();
$this->model = $this->model->newQuery();
$this->model->select("{$table}.*");
$this->prepare($this->model);
if ($this->onlyVisible) {
$this->filterVisible($this->model);
}
if ($this->onlyAuthored) {
$this->filterAuthored($this->model);
}
$this->filter($this->model, $this->filters);
$this->model->where($table . '.' . $this->identifier, '=', $id);
$result = $orFail ? $this->model->firstOrFail() : $this->model->first();
$this->storeToCache($result);
$this->clearFilters();
return $result;
}
示例7: getRelationCountQueryForSelfRelation
/**
* Add the constraints for a relationship count query on the same table.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationCountQueryForSelfRelation(Builder $query, Builder $parent)
{
$query->select(new Expression('count(*)'));
$query->from($query->getModel()->getTable() . ' as ' . ($hash = $this->getRelationCountHash()));
$key = $this->wrap($this->getQualifiedParentKeyName());
return $query->where($hash . '.' . $this->getPlainForeignKey(), '=', new Expression($key));
}
示例8: scopeExcludeFromFind
/**
* Exclude from find
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeExcludeFromFind(Builder $query)
{
if (isset($this->excludedFromFind) == TRUE && is_array($this->excludedFromFind) == TRUE) {
return $query->select(array_diff(Schema::getColumnListing($this->table), $this->excludedFromFind));
} else {
return $query;
}
}
示例9: rememberForever
/**
* Store the result on cache forever
*
* @param array $columns
* @return mixed
*/
public function rememberForever(array $columns = ['*'])
{
$this->applyCriteria();
$this->builder->select($columns);
return Cache::rememberForever($this->generateCacheKey(), function () use($columns) {
return $this->all($columns);
});
}
示例10: select
/**
* Attach the name of the table to each column of the select if possible
*
* @param array $columns
* @return mixed
*/
public function select($columns = ['*'])
{
$columns = !is_array($columns) ? [$columns] : $columns;
foreach ($columns as $key => $column) {
$columns[$key] = $this->getModelTableColumn($column);
}
return parent::select($columns);
}
示例11: count
/**
* Returns the count for a countable parameter, given the query provided
*
* @param string $name
* @param EloquentBuilder $query
* @param CountableFilterInterface $filter
* @return array
*/
public function count($name, $query, CountableFilterInterface $filter)
{
// if the columnname is not set, assume an id field based on a table name
$columnName = empty($this->columnName) ? $name : $this->columnName;
if (!$this->includeEmpty) {
$query->whereNotNull($columnName);
}
return $query->select("{$columnName} AS {$this->columnAlias}", DB::raw("{$this->countRaw} AS {$this->countAlias}"))->groupBy($columnName)->pluck($this->countAlias, $this->columnAlias);
}
示例12: excludeCriterion
public function excludeCriterion(QueryBuilder $query, $columns)
{
$columns = static::getArgumentsArray($columns, func_get_args());
// Get the attributes of the model and filter out all but specified
$schema = $query->getQuery()->getConnection()->getSchemaBuilder();
$allColumns = $schema->getColumnListing($query->getModel()->getTable());
$difference = array_diff($allColumns, $columns);
return $query->select($difference);
}
示例13: 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}");
}
示例14: scopeFilterByAdminGrid
/**
* @param Builder $query
* @param $filters
* @param $currentUserId
*/
public function scopeFilterByAdminGrid(Builder $query, $filters, $currentUserId)
{
$query->select([User::getTableName() . '.*', 'up.*'])->join(Profile::getTableName() . ' AS up', 'up.user_id', '=', User::getTableName() . '.id', 'right');
foreach ($filters as $filterKey => $filterValue) {
if (empty($filterValue)) {
continue;
}
switch ($filterKey) {
case 'fname':
$query->where('fname', 'LIKE', '%' . $filterValue . '%');
break;
case 'email':
$query->where('email', 'LIKE', '%' . $filterValue . '%');
break;
}
}
$query->where('id', '!=', $currentUserId);
}
示例15: buildQuery
private function buildQuery()
{
$this->query = app(get_class($this->model));
if (!empty($this->fields)) {
$this->query = $this->query->select($this->fields);
}
if (!empty($this->relations)) {
$this->relations = array_unique($this->relations);
$this->query = $this->query->with($this->relations);
}
if (!empty($this->per_page)) {
$this->query = $this->query->take($this->per_page);
}
if (count($this->conditions)) {
foreach ($this->conditions as $condition) {
$this->query = $this->query->where($condition['column'], $condition['operator'], $condition['value'], $condition['boolean']);
}
}
}