title: Laravel: How to load a 'belongs to' as a dynamic property?
body: <p>I have 2 models: <code>user</code> and <code>state</code>.  A state is where the user lives, so a state has many users, and a user belongs to one state.</p>
  
  <p>In my user model I have a belongs-to relationship, as follows:</p>
  
  <pre><code>public function state()
  {
      return $this-&gt;belongsTo(State::class);
  }
  </code></pre>
  
  <p>When I access <code>$user-&gt;state</code> I want the result of the db query, however since <code>$user</code> has a state value, it returns that instead.  Is there a way to change this behaviour through configuration?</p>
  
  <p>I tried creating a <code>getStateAttribute()</code> method, and returning <code>$this-&gt;belongsTo(State::class)</code>, but Laravel doesn't like that.  At the moment, the only way I can retrieve the state object is through:</p>
  
  <pre><code>$user-&gt;state()-&gt;first();
  </code></pre>
  
  <p>The problem doesn't exist when the property name is two words, e.g. <code>$user-&gt;firstName</code>, because my column names are all snake case (i.e. there are no naming conflicts.)</p>