title: Setting up a kind of BelongsToThrough relationship in Laravel
body: <p>Here is my current situation:</p>
  <ul>
  <li>I have a Task model.</li>
  <li>Tasks have owners (a belongsTo relationship)</li>
  <li>Owners have accounts (yet another belongsTo relationship)</li>
  </ul>
  <p>I'd like to set up a &quot;belongsToThrough&quot; relationship from Tasks to Accounts.</p>
  <p>My first solution was to define a relationship in the Tasks model, like this:</p>
  <pre class="lang-php prettyprint-override"><code>    public function account(): BelongsTo
      {
          return $this-&gt;owner-&gt;account();
      }
  </code></pre>
  <p>With it I could call <code>$task-&gt;account</code> and retrieve a task's account easily. The problem is that this doesn't work with <code>load</code>/<code>with</code>, which in turn causes problems because I can't <code>refresh()</code> a task that has had the account loaded in (because refresh uses load). The error just states <code>Trying to call account() on null</code> which was honestly expected.</p>
  <p>My second solution was to change the relationship method to:</p>
  <pre class="lang-php prettyprint-override"><code>    public function account(): BelongsTo
      {
          return $this-&gt;owner()-&gt;first()-&gt;account();
      }
  </code></pre>
  <p>With this, I can also simply call <code>$task-&gt;account</code> and retrieve the model, and when loading, it doesn't work (returns null), but also doesn't throw any errors. I don't need to load this relationship in, it just happens that sometimes I need to refresh models and having the load method throw an error is not ok.</p>
  <p><strong>In summary</strong></p>
  <p>What I'm looking for is kind of a BelongsToThrough, as a Task would BelongTo an Account through an Owner (User). Is there a way to do this that works using both <code>$task-&gt;account</code> and <code>$task-&gt;load('account')</code>. Before you tell me I can load it using <code>owner.account</code>, I know that, but <code>refresh()</code> will do it automatically with <code>load('account')</code> so I need it to work like that, not with the dot notation.</p>