How to get count for all products for all categories (i.e all records on many-to-many table) with laravel 5.2
<p>This what i want to do is to take the count of records from many-to-many table. I can do it with a simple query, but I want to use the ORM of Laravel 5.2. These are my models:</p>

<p>Category model</p>

<pre><code>class Category extends BaseModel {
    protected $table = 'categories';

    public function products() {
        return $this-&gt;belongsToMany('App\Models\Product', 'product_category');
    }
</code></pre>

<p>Product model</p>

<pre><code>class Product extends BaseModel {
    protected $table = 'products';

    public function categories() {
        return $this-&gt;belongsToMany('App\Models\Category', 'product_category')-&gt;withTimestamps();
    }
</code></pre>

<p>I want to add a method in the Category model or using the Laravel ORM to take the number of all products for all categories i.e the number of all records from the <code>product_category</code> table. How can I do it ?</p>