title: How to eager load a relation with a condition in Eloquent?
body: <p>I have a relation that can be inherited from a parent if not set for the object itself.</p>
  
  <p>For an example setup let's say we have events that have a venue.</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>class Event extends Model
  {
      public function venue()
      {
          return $this-&gt;belongsTo('App\Venue');
      }
  
      public function activities()
      {
          return $this-&gt;hasMany('App\Activity');
      }
  }
  </code></pre>
  
  <p>And there are activities in the events that mostly take place in the same venue, but sometimes could be elsewhere while still belonging to the same event.</p>
  
  <pre class="lang-php prettyprint-override"><code>class Activity extends Model
  {
      public function event()
      {
          return $this-&gt;belongsTo('App\Event');
      }
  
      public function venue()
      {
          if ($this-&gt;venue_id)
              return $this-&gt;belongsTo('App\Venue');
  
          return $this-&gt;event-&gt;venue();
      }
  }
  </code></pre>
  
  <p>If I simply request activities for an event and work with them it is fine. But if I try to eager load the venues for activities, I only get the ones that are set directly on the activity, never requesting one from parent.</p>
  
  <pre class="lang-php prettyprint-override"><code>$activities = $event-&gt;activities;
  $activities-&gt;load('venue');  // Works correctly without this line
  
  foreach ($activities as $activity)
      if ($activity-&gt;venue)    // Doesn't take venue from the parent (event)
          echo $activity-&gt;venue-&gt;name;  //Only shows if venue_id is set on activity
  </code></pre>
  
  <p>Is there any chance to fix the relations so I could load them in bulk?</p>