title: Refer to relationship in Laravel Eloquent scope
body: <p>Laravel 5.7. I have a model <code>Cat</code>, with a property <code>visible</code>, and a scope to check for visibility:</p>
  
  <pre><code>class Cat extends Model
  {
      public function scopeVisible($query)
      {
          return $query-&gt;where('visible', true);
      }
  
      public function fleas()
      {
          return $this-&gt;hasMany('App\Flea');
      }
  }
  </code></pre>
  
  <p>I have a second model, <code>Flea</code>:</p>
  
  <pre><code>class Flea extends Model
  {
      public function cat()
      {
          return $this-&gt;belongsTo('App\Cat');
      }
  }
  </code></pre>
  
  <p>I want to add a similar visibility scope to <code>Flea</code>, so that I would be able to do something like <code>$fleas = Flea::visible()-&gt;get()</code>, which would only return Fleas which belong to visible Cats. But I'm not sure how I can reference the parent <code>Cat</code> in the scope method on <code>Flea</code>.</p>
  
  <p>Edit: I try to access the <code>cat()</code> relationship in a <code>scopeVisible</code> method on <code>Flea</code>, but I get this error from Laravel:</p>
  
  <blockquote>
    <p>Property [cat] does not exist on the Eloquent builder instance.</p>
  </blockquote>