title: How to use laravel query builder to get the count, distinct and total country
body: <p>I want to use laravel query builder to calculate based on country that participate in the competition.</p>
  
  <pre><code>Table country:
  ------------------
  country_id
  country_name
  
  Table company:
  -----------------
  company_id
  company_name
  country_id(fk)
  
  Table_participate_company:
  -------------------------
  company_id
  competition_id
  
  Table competition:
  --------------------
  competition_id
  competition_name
  </code></pre>
  
  <p>Sample output:</p>
  
  <p><a href="https://i.stack.imgur.com/JGFuK.png" rel="nofollow noreferrer">Sample output</a></p>
  
  <h2>My current query:</h2>
  
  <pre><code>$total = DB::table('company')
                      -&gt;join('participate_company', 'company.company_id', '=','participate_company.company_id')
                      -&gt;join('country', 'company.country_id', '=','country.country_id')  
                      -&gt;get();
  </code></pre>