title: Eager loading related model using query scope
body: <p>Say I have a model <code>Box</code> which holds many widgets. The widgets can be active or inactive (boolean). The <code>Widget</code> model has a query scope which can filter results:</p>
  
  <p>models/box.php:</p>
  
  <pre class="lang-js prettyprint-override"><code>class Box extends Eloquent
  {
      public function widgets()
      {
          return $this-&gt;hasMany('Widget');
      }
  }
  </code></pre>
  
  <p>models/widget.php:</p>
  
  <pre class="lang-js prettyprint-override"><code>class Widget extends Eloquent {
  
      public function box()
      {
          return $this-&gt;belongsTo('Box');
      }
  
      public function scopeActive($query)
      {
          return $query-&gt;whereActive(true);
      }
  }
  </code></pre>
  
  <p>Query scopes make it easy to get all widgets for a given box:</p>
  
  <pre class="lang-js prettyprint-override"><code>$box_widgets = Box::find($box_id)-&gt;widgets()-&gt;active()-&gt;get(); 
  // returns an Eloquent\Collection containing a filtered array of widgets
  </code></pre>
  
  <p>But how can I use <code>scopeActive</code> to eliminate this eager loading <code>with</code> method's conditional function? </p>
  
  <pre class="lang-js prettyprint-override"><code>$boxes = Box::with(array('widgets', function ($q)
  {
      $q-&gt;active();
  }))-&gt;get();
  </code></pre>
  
  <p>It seems like there's probably a shorthand for accessing a relation's scope,  something like <code>Box::with('widgets-&gt;active')</code> or <code>Box::with('widgets.active')</code> but I haven't been able to find it. </p>