protected function assembleQuery($initial, $recursive)
    {
        $tmp_tbl = 'name_tree';
        $recursive = str_replace(':tmp_tbl', $tmp_tbl, $recursive);

        $final = "select distinct * from $tmp_tbl";

        if (DB::connection()->getDriverName() == 'mysql') {
            return "Call WITH_EMULATOR('$tmp_tbl', '$initial', '$recursive', '$final', 0, 'ENGINE=MEMORY');";
        }

        return "WITH RECURSIVE $tmp_tbl AS ($initial UNION ALL $recursive) $final;";
    }
protected function assembleQuery($initial, $recursive)
    {
        $tmp_tbl = 'name_tree';
        $recursive = str_replace(':tmp_tbl', $tmp_tbl, $recursive);

        $final = "select distinct * from $tmp_tbl";

        if (DB::connection()->getDriverName() == 'mysql') {
            return "Call WITH_EMULATOR('$tmp_tbl', '$initial', '$recursive', '$final', 0, 'ENGINE=MEMORY');";
        }

        return "WITH RECURSIVE $tmp_tbl AS ($initial UNION ALL $recursive) $final;";
    }
protected function assembleQuery ( $ initial , $ recursive ) { $ tmp_tbl = 'name_tree' ; $ recursive = str_replace ( ':tmp_tbl' , $ tmp_tbl , $ recursive ) ; $ final = "select distinct * from $tmp_tbl" ; if ( DB :: connection ( ) -> getDriverName ( ) == 'mysql' ) { return "Call WITH_EMULATOR('$tmp_tbl', '$initial', '$recursive', '$final', 0, 'ENGINE=MEMORY');" ; } return "WITH RECURSIVE $tmp_tbl AS ($initial UNION ALL $recursive) $final;" ; }
Prepare the complete query to run on the DB to get the data recursively.

@param string $initial The initial query bootstrapping the recursive query
@param string $recursive The query to dig deeper in the hierarchy
@return string
Prepare the complete query to run on the DB to get the data recursively .