title: Error when fetching category posts
body: <p>I made simple CMS using laravel and when i try to get posts inside single category page.Using <strong>$category->posts()</strong> which i assigned in my category model but for some reason it's not defined and i get the following error
  <a href="https://i.stack.imgur.com/twipz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/twipz.png" alt="enter image description here"></a></p>
  
  <p>And here is my codes</p>
  
  <p><strong>Category Model</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Category extends Model
  {
      protected $table = 'categories';
  
      public function posts() 
      {
          return $this-&gt;belongsToMany('App\Posts')-&gt;withTimestamps();
      }
  }
  </code></pre>
  
  <p><strong>Post Model</strong></p>
  
  <pre><code>        &lt;?php
  
      namespace App;
  
      use Illuminate\Database\Eloquent\Model;
  
      class Post extends Model
      {
          public function categories() 
          {
              return $this-&gt;belongsToMany('App\Category')-&gt;withTimestamps();
          }
  
          public function user() 
          {
              return $this-&gt;belongsTo('App\User');
          }
  
          public function meta() 
          {
              return $this-&gt;hasMany('App\Postmeta');
          }
      }
  
  **Category Controller**
  &lt;?php
  
  namespace App\Http\Controllers\Frontend;
  
  use Illuminate\Http\Request;
  use App\Http\Controllers\Controller;
  use App\Category;
  
  class CategoriesController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function getIndex()
      {
          return view('frontend.categories.index')-&gt;withCategories(Category::orderBy('id', 'desc')-&gt;paginate(6));
      }
  
      /**
       * Display the specified resource.
       *
       * @param  int  $slug
       * @return \Illuminate\Http\Response
       */
      public function getSingle($slug)
      {
          $category   = Category::where('slug', '=', $slug)-&gt;first();
          $posts      = ($category !== null) ? $category-&gt;posts() : array();
  
          return view('frontend.categories.single')-&gt;withCategory($category)-&gt;withPosts($posts);
      }
  }
  </code></pre>