title: How to get category a product belongs to - Laravel 6
body: <p>I am fetching products and in the response, i want the category it belongs to to appear in the response. When i log the response, it looks like the below</p>
  <p><strong>Response</strong></p>
  <pre><code> [{&quot;items_receive&quot;:&quot;280&quot;,&quot;category&quot;:null},`{&quot;items_receive&quot;:&quot;100&quot;,&quot;category&quot;:null}]`  
  </code></pre>
  <p><strong>Product.php</strong></p>
  <pre><code>public function category()
  {
      return $this-&gt;belongsTo(Category::class);
  }
  
   public function getSummary()
      {
          return Product::with('category')-&gt;selectRaw('SUM(items_receive) as 
           items_total)
                  -&gt;where('user_id',Auth::user()-&gt;id)
                  -&gt;groupBy('category_id')
                  -&gt;get();
      }
  </code></pre>
  <p><strong>Category.php</strong></p>
  <pre><code> public function products()
      {
          return $this-&gt;hasMany(Product::class);
      }
  </code></pre>
  <p><strong>Controller.php</strong></p>
  <pre><code> public function index(Product $product)
   {
         $product-&gt;getSummary(); 
   }
  </code></pre>