本文整理汇总了PHP中Illuminate\Database\Query\Builder::addSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::addSelect方法的具体用法?PHP Builder::addSelect怎么用?PHP Builder::addSelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Query\Builder
的用法示例。
在下文中一共展示了Builder::addSelect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
public function apply(QueryBuilder $builder)
{
if (!$this->request->has('_DatatableQuery') || !isset($this->filters->idField)) {
$builder->addSelect($this->db->raw('0 as _checked'));
return $builder;
}
$this->filters->items[] = -1;
if ($this->filters->checkedAll) {
$builder->addSelect($this->db->raw('(case when ' . $this->filters->idField . ' IN (' . implode(',', $this->filters->items) . ') then 0 else 1 end) as _checked'));
return $builder;
}
$builder->addSelect($this->db->raw('(case when ' . $this->filters->idField . ' IN (' . implode(',', $this->filters->items) . ') then 1 else 0 end) as _checked'));
return $builder;
}
示例2: parseFullTextSearch
/**
* Parse the fulltext search parameter q
*
* @param string $qParam
* @param array $fullTextSearchColumns
* @return void
*/
protected function parseFullTextSearch($qParam, $fullTextSearchColumns)
{
if ($qParam == '') {
//Add where that will never be true
$this->query->whereRaw('0 = 1');
return;
}
$fulltextType = Config::get('apihandler.fulltext');
if ($fulltextType == 'native') {
//Use pdo's quote method to be protected against sql-injections.
//The usual placeholders unfortunately don't seem to work using AGAINST().
$qParam = $this->query->getConnection()->getPdo()->quote($qParam);
//Use native fulltext search
$this->query->whereRaw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE)');
//Add the * to the selects because of the score column
if (count($this->query->columns) == 0) {
$this->query->addSelect('*');
}
//Add the score column
$scoreColumn = Config::get('apihandler.fulltext_score_column');
$this->query->addSelect($this->query->raw('MATCH(' . implode(',', $fullTextSearchColumns) . ') AGAINST("' . $qParam . '" IN BOOLEAN MODE) as `' . $scoreColumn . '`'));
} else {
$keywords = explode(' ', $qParam);
//Use default php implementation
$this->query->where(function ($query) use($fullTextSearchColumns, $keywords) {
foreach ($fullTextSearchColumns as $column) {
foreach ($keywords as $keyword) {
$query->orWhere($column, 'LIKE', '%' . $keyword . '%');
}
}
});
}
}
示例3: checkQuerySelects
protected function checkQuerySelects()
{
$selects = $this->query->getQuery()->columns;
$tableSelect = $this->model->getTable() . '.*';
if (empty($selects) || !in_array($tableSelect, $selects)) {
$this->query->addSelect($tableSelect);
}
}
示例4: scopeJoinWithSelect
/**
* @param \Illuminate\Database\Query\Builder $query
* @param string $table join the table
* @param string $one joins first parameter
* @param string|array|null $operatorOrCollumns operator condition or collums list
* @param string $two joins two parameter
* @param string $type join type (left, right, '', etc)
* @param bool|false $where custom where condition
* @param array $collumns if you will not pass collumns, it will retreive the collumn listing. If you pass null
* it will not get any data from the model.
*
* @return \Illuminate\Database\Query\Builder
*/
public function scopeJoinWithSelect($query, $table, $one, $operatorOrCollumns, $two, $type = "left", $where = false, $collumns = array())
{
// if the operator collumns are in
if (is_array($operatorOrCollumns) || is_null($operatorOrCollumns)) {
$collumns = $operatorOrCollumns;
$operatorOrCollumns = "=";
}
if (!is_null($collumns)) {
// if there is no specific collumns, lets get all
if (empty($collumns)) {
$collumns = \Schema::getColumnListing($table);
}
// build the table values prefixed by the table to ensure unique values
foreach ($collumns as $related_column) {
$query->addSelect(new Expression("`{$table}`.`{$related_column}` AS `{$table}.{$related_column}`"));
}
}
return $query->join($table, $one, $operatorOrCollumns, $two, $type, $where);
}
示例5: 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;
}
示例6: addSelect
/**
* Add a new select column to the query.
*
* @param array|mixed $column
* @return $this
* @static
*/
public static function addSelect($column)
{
return \Illuminate\Database\Query\Builder::addSelect($column);
}