title: Laravel belongsTo with condition and eager load
body: <p>I have a <strong>Post</strong> model associated to a <strong>Section</strong> model, which depend on an extra condition to work:</p>
  
  <pre><code>&lt;?php
  class Post extends Base
  {
      public function section()
      {
          return $this-&gt;belongsTo('App\Models\Section', 'id_cat')-&gt;where('website', $this-&gt;website);
      }
  }
  </code></pre>
  
  <p>When I want to retrieve a Post and get it's associated section, I can do it as:</p>
  
  <pre><code>$post = Post::first();
  echo $post-&gt;section-&gt;name; // Output the section's name
  </code></pre>
  
  <p>However, when trying to get the section using an eager load:</p>
  
  <pre><code>Post::with(['section'])-&gt;chunk(1000, function ($posts) {
      echo $post-&gt;section-&gt;name;
  });
  </code></pre>
  
  <p>Laravel throw the following exception : </p>
  
  <pre><code>PHP error:  Trying to get property of non-object
  </code></pre>
  
  <p>When I do a debug of a Post object returned by the above eager load query, I notice that the <code>section</code> relationship is <code>null</code>.
  Note that it is working fine if I remove the condition from the <code>belongsTo</code> association.</p>
  
  <p>Do you guys have any ideas why it's happening?</p>