Create the handler.

@param mixed $query
@param mixed $builder

@return \Jenky\LaravelApiHelper\Handler
761582
protected function createHandler($query, $builder = null)
    {
        $handler = new Handler($this->request, $this->config);

        $handler->setQuery($query);

        if (! is_null($builder)) {
            $handler->setBuilder($builder);
        }

        return $handler;
    }
962616
public function createSearch($query = '', $options = null, BuilderInterface $builder = null)
    {
        $search = new Search($this->getClient(), $builder);
        $search->addIndex($this);
        $search->setOptionsAndQuery($options, $query);

        return $search;
    }
503900
public function compileSelect(Builder $query) {
    $this->beforeGet($query);
    return $this->grammar->compileSelect($query);
  }
881567
public function resolve($query)
    {
        $queryClassName = self::findBaseName($query);
    
        if ($query instanceof ICommand) {
            
            if (isset($this->commandHandlers[$queryClassName])) {
                return $this->commandHandlers[$queryClassName];
            }
            
            throw new HandlerNotFoundException($queryClassName);
        }
        
        // if its not a command, then it must be a query
        if (isset($this->queryHandlers[$queryClassName])) {
            return $this->queryHandlers[$queryClassName];
        }
        
        throw new HandlerNotFoundException($queryClassName);
    }
435258
protected function compileComponents(Builder $query)
    {
        $sql = [];

        foreach ($this->selectComponents as $component) {
            // To compile the query, we'll spin through each component of the query and
            // see if that component exists. If it does we'll just call the compiler
            // function for the component which is responsible for making the SQL.
            if (isset($query->$component) && ! is_null($query->$component)) {
                $method = 'compile'.ucfirst($component);

                $sql[$component] = $this->$method($query, $query->$component);
            }
        }

        return $sql;
    }
1226117
protected function setKeysForSaveQuery(Builder $query)
    {
        $query->where($this->morphType, $this->morphClass);

        return parent::setKeysForSaveQuery($query);
    }
530713
public function compileSelect(Builder $query)
    {
        if (! $query->offset) {
            return parent::compileSelect($query);
        }

        // If an offset is present on the query, we will need to wrap the query in
        // a big "ANSI" offset syntax block. This is very nasty compared to the
        // other database systems but is necessary for implementing features.
        if (is_null($query->columns)) {
            $query->columns = ['*'];
        }

        return $this->compileAnsiOffset(
            $query, $this->compileComponents($query)
        );
    }
1007724
protected function compileComponents(Builder $query)
    {
        $request = [];

        foreach ($this->requestComponents as $component) {
            // To compile the query, we'll spin through each component of the query and
            // see if that component exists. If it does we'll just call the compiler
            // function for the component which is responsible for making the request.
            if (!is_null($query->$component)) {
                $method = 'compile' . ucfirst($component);

                $request[$component] = $this->$method($query, $query->$component);
            }
        }

        return $request;
    }
115319
protected function search(Builder $query)
    {
        $q = request('q');

        if (!$q || strlen($q) < $this->minimumSearchInputLength)
            return $query;

        return $this->searchQuery($query, $q);
    }
887594
protected function makeJoins(Builder $query)
    {
        foreach ($this->getJoins() as $table => $keys) {
            $query->leftJoin($table, function ($join) use ($keys) {
                $join->on($keys[0], '=', $keys[1]);
                if (array_key_exists(2, $keys) && array_key_exists(3, $keys)) {
                    $join->whereRaw($keys[2] . ' = "' . $keys[3] . '"');
                }
            });
        }
    }
961657
public function compileSelect(Builder $query)
    {
        if ($query->unions && $query->aggregate) {
            return $this->compileUnionAggregate($query);
        }

        $sql = parent::compileSelect($query);

        if ($query->unions) {
            $sql = '('.$sql.') '.$this->compileUnions($query);
        }

        return $sql;
    }
575563
protected function prefixWheres(Builder $query, $prefix)
    {
        if (is_array($query->getQuery()->wheres))
        {
            $query->getQuery()->wheres = array_map(function($where) use($prefix)
            {
                $column = $where['column'];
                $where['column'] = ($this->isId($column)) ? $column : $prefix .'.'. $column;
                return $where;
            }, $query->getQuery()->wheres);
        }
    }
310950
public function scopeClients(Builder $query)
    {
        $query->with('roles')->whereNotNull('tbl_users.id')->whereHas('roles', function ($query) {
            $query->whereIn('tbl_roles.name', ['member', 'users', 'user']);
        });


        return $query;
    }
415632
public function compileSelect(Builder $query)
	{
		$original = $query->columns;

		if (is_null($query->columns)) {
			$query->columns = ['*'];
		}

		$components = $this->compileComponents($query);

		// If an offset is present on the query, we will need to wrap the query in
		// a big "ANSI" offset syntax block. This is very nasty compared to the
		// other database systems but is necessary for implementing features.
		if ($query->offset > 0) {
			return $this->compileAnsiOffset($query, $components);
		}

		$sql = $this->concatenate($components);

		$query->columns = $original;

		return $sql;
	}
219677
public function newEloquentBuilder($query)
    {
        $builder = new TaxonomyBuilder($query);

        return isset($this->taxonomy) && $this->taxonomy ? $builder->where('taxonomy', $this->taxonomy) : $builder;
    }
90077
protected function performJoin(Builder $query = null)
    {
        $query = $query ?: $this->query;

        $farKey = $this->getQualifiedFarKeyName();

        $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $farKey);

        if ($this->throughParentSoftDeletes()) {
            $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn());
        }
    }
398739
public function scopeAdministrators(Builder $query)
    {
        $query->with('roles')->whereNotNull('tbl_users.id')->whereHas('roles', function ($query) {
            $query->whereNotIn('tbl_roles.name', ['member', 'guest', 'client']);
        });


        return $query;
    }