title: Laravel. Use scope() in models with relation
body: <p>I have two related models: <code>Category</code> and <code>Post</code>.</p>
  
  <p>The <code>Post</code> model has a <code>published</code> scope (method <code>scopePublished()</code>).</p>
  
  <p>When I try to get all categories with that scope:</p>
  
  <pre><code>$categories = Category::with('posts')-&gt;published()-&gt;get();
  </code></pre>
  
  <p>I get an error: </p>
  
  <blockquote>
    <p>Call to undefined method <code>published()</code></p>
  </blockquote>
  
  <p><strong>Category:</strong></p>
  
  <pre><code>class Category extends \Eloquent
  {
      public function posts()
      {
          return $this-&gt;HasMany('Post');
      }
  }
  </code></pre>
  
  <p><strong>Post:</strong></p>
  
  <pre><code>class Post extends \Eloquent
  {
     public function category()
     {
         return $this-&gt;belongsTo('Category');
     }
  
  
     public function scopePublished($query)
     {
         return $query-&gt;where('published', 1);
     }
  
  }
  </code></pre>