addSelect() public method

Add a new select column to the query.
public addSelect ( array | mixed $column )
$column array | mixed
 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;
 }
 /**
  * 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 . '%');
                 }
             }
         });
     }
 }
 protected function checkQuerySelects()
 {
     $selects = $this->query->getQuery()->columns;
     $tableSelect = $this->model->getTable() . '.*';
     if (empty($selects) || !in_array($tableSelect, $selects)) {
         $this->query->addSelect($tableSelect);
     }
 }
Example #4
0
 /**
  * @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);
 }
Example #5
0
 /**
  * Очень простая фильтрация скоупов.
  *
  * Если необходимо отфильтровать скоупы по 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;
 }
Example #6
0
 /**
  * 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);
 }