title: Count data from database on laravel
body: <p>On php i could use this code to get how many item on my goods db </p>
  
  <pre><code>$total = 0;
  $sql = "select count(*) as total from goods";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      while($row = $result-&gt;fetch_assoc()) {
          $total = $row['total'];
      }
  }
  echo $total;
  // example return 5
  </code></pre>
  
  <p>can i do that on laravel? if i use this code on my controller </p>
  
  <pre><code>function show(Request $request){
      $c = DB::select("SELECT count(*) as total FROM goods");
      if($c &gt; 0 ): a ? b;
  }
  </code></pre>
  
  <p>it would get error message since it would return JSON inside array. Are there any better way to do this? Or how to get that total from $c inside controller</p>