Eloquent merge two queries

Published 2 months ago by cunlayogd

Hi all, how can I merge this two queries into a single query.

$jobLocations = DB::table('job_post_locations')
                     ->join('locations', 'job_post_locations.location_id', '=', 'locations.id')
                     ->select('locations.id','locations.name',DB::raw('count(*) as location_count'))

        $jobIndustries = DB::table('job_post_industries')
                     ->join('industries', 'job_post_industries.industry_id', '=', 'industries.id')
                     ->select('industries.id','industries.name',DB::raw('count(*) as industry_count'))

@cunlayogd First of all can you put your code in the ``` so everyone can actually read this: https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code


@mballaag thank you, I have formatted the code


Use unions https://laravel.com/docs/5.6/queries#unions

$first = DB::table('users')

$users = DB::table('users')

Please sign in or create an account to participate in this conversation.