title: Counting total posts by a user in the blade view
body: <p>I have sent a collection of all posts in my blog to my index view and then used the following code to count the total posts made by each user.</p>
  
  <pre><code>&lt;p class="joined-text"&gt;Posts: {{count(App\Posts::where('user_id', $post-&gt;user-&gt;id)-&gt;get())}}&lt;/p&gt;
  </code></pre>
  
  <p>Is this bad practice to do this from within the blade view?  If it is how would I achieve this?</p>
  
  <p>Models</p>
  
  <pre><code>class Posts extends Model
  {
      public function user()
      {
          return $this-&gt;belongsTo(User::class);
      }
  
      public function comments()
      {
          return $this-&gt;hasMany(Comments::class, 'post_id');
      }
  }
  
  
  
  
  
  class User extends Authenticatable
  {
  
      public function posts()
      {
          return $this-&gt;hasMany('\App\Posts::class');
      }
  
      public function comments()
      {
          return $this-&gt;hasMany(Comments::class);
      }
  }
  </code></pre>