Apply query method to two instances

I am trying to apply a query call


Class::getAllContributions('account_id,perk_id',same as what follows)->where('id'=>1)->andWhere('secondArg'=>2)

to two query instances. The methods get called fine for $allPerks but obviously do not get applied to $perks. So the question is how do I apply the method calls to both? I know the $addonQueries part is wrong but its the best way to illustrate what I am trying to do.


public function getAllContributions($fields = 'perk_id, label',$addonQueries = null){

        $perks = (new Query())

            ->select($fields)

            ->from('table1')

            ->$addonQueries;


        $allPerks = (new Query())

            ->select($fields)

            ->from('table2')

            ->union($perks);


        if(!$addonQueries==null){

            return $allPerks->all();

        }else{

            return $allPerks;

        }


    }

Ignoring the


$addonQueries 

I basically get


(new Query())

            ->select($fields)

            ->from('table2')

            ->where('id'=>1)->andWhere('secondArg'=>2)

            ->union(

                   (new Query())->select($fields)->from('table1')

            )

Whereas what I would like is:


(new Query())

            ->select($fields)

            ->from('table2')

            ->where('id'=>1)->andWhere('secondArg'=>2)

            ->union(

                   (new Query())->select($fields)->from('table1')->where('id'=>1)->andWhere('secondArg'=>2)

            )

Thank you for the help!


public function getAllContributions($fields = 'perk_id, label',$addonConditions =[],$addonQueries = null){

        $perks = (new Query())

            ->select($fields)

            ->from('table1')

            ->where($addonConditions);


        $allPerks = (new Query())

            ->select($fields)

            ->from('table2')

            ->where($addonConditions)

            ->union($perks);


        if(!$addonQueries==null){

            return $allPerks->all();

        }else{

            return $allPerks;

        }


    }