private function getQuery() { $concat = []; foreach ($this->by as $id) { $concat[] = "ifnull(`{$id}`,'')"; } $key = "concat(" . implode(",'-',", $concat) . ") as `__key`"; $columns = implode(",", array_merge([$key], $this->sync)); return $this->builder->selectRaw($columns); }
/** * Apply relevance select on the subquery. * * @param \Sofa\Searchable\Subquery $subquery * @param \Sofa\Searchable\ColumnCollection $columns * @param array $words * @return array */ protected function searchSelect(array $columns, array $words) { $cases = $bindings = []; foreach ($columns as $column) { list($cases[], $binding) = $this->buildCase($column, $words); $bindings = array_merge_recursive($bindings, $binding); } $select = implode(' + ', $cases); $this->query->selectRaw("max({$select}) as relevance", $bindings['select']); return $bindings['where']; }
/** * Add a new "raw" select expression to the query. * * @param string $expression * @param array $bindings * @return \Illuminate\Database\Query\Builder|static * @static */ public static function selectRaw($expression, $bindings = array()) { return \Illuminate\Database\Query\Builder::selectRaw($expression, $bindings); }
/** * Add a new "raw" select expression to the query. * * @param string $expression * @return \Illuminate\Database\Query\Builder|static * @static */ public static function selectRaw($expression) { return \Illuminate\Database\Query\Builder::selectRaw($expression); }
/** * Get tags that have been used more than 3 times and * include that count with the tag. * * @param \Illuminate\Database\Query\Builder $query * @return \Illuminate\Database\Query\Builder */ public function scopeUsed($query) { return $query->selectRaw('tags.*, COUNT(id) AS count')->join('post_tag', 'post_tag.tag_id', '=', 'tags.id')->groupBy('slug'); }
/** * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query * @return void */ public function applyQuery($query) { $query->selectRaw($this->getSQLSelect($query->from) . ' as __interval__'); $query->groupBy('__interval__'); }
/** * Add the role inheritence "where" clause to the given query. * * @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Eloquent\Model $authority * @param string $roles * @return \Closure */ protected function addRoleInheritCondition(Builder $query, Model $authority, $roles) { $query->orWhere('level', '<', function ($query) use($authority, $roles) { $query->selectRaw('max(level)')->from($roles)->whereExists($this->getAuthorityRoleConstraint($authority)); }); }