protected function parseAliases(Builder $query)
    {
        $aliases = [];

        if (!empty($query->getQuery()->columns)) {
            $aliases = $this->getAliases($query);
        }

        if (!empty($aliases) && !empty($query->getQuery()->wheres)) {
            $this->replaceAliases($query, $aliases);
        }

        return $query;
    }
protected function parseAliases(Builder $query)
    {
        $aliases = [];

        if (!empty($query->getQuery()->columns)) {
            $aliases = $this->getAliases($query);
        }

        if (!empty($aliases) && !empty($query->getQuery()->wheres)) {
            $this->replaceAliases($query, $aliases);
        }

        return $query;
    }
protected function parseAliases ( Builder $ query ) { $ aliases = [ ] ; if ( ! empty ( $ query -> getQuery ( ) -> columns ) ) { $ aliases = $ this -> getAliases ( $ query ) ; } if ( ! empty ( $ aliases ) && ! empty ( $ query -> getQuery ( ) -> wheres ) ) { $ this -> replaceAliases ( $ query , $ aliases ) ; } return $ query ; }
Replace alias name in where closure with sub-queries from select.

Example:

SELECT table.*, (SELECT 1 FROM other_table ot WHERE ot.id = table.id) AS exists
WHERE exists = 1;

Will be converted to:

SELECT table.*, (SELECT 1 FROM other_table ot WHERE ot.id = table.id) AS exists
WHERE (SELECT 1 FROM other_table ot WHERE ot.id = table.id) = 1;

@param Builder $query

@return Builder
Replace alias name in where closure with sub - queries from select .