title: Laravel 4: How to add more data to Auth::user() without extra queries?
body: <p>I'm rather new to Laravel 4 and can't seem to find the right answer, maybe you can help:</p>
  
  <p>A User in our application can have many Accounts and all data is related to an Account, not a User. The account the User is currently logged into is defined by a subdomain, i.e. accountname.mydomain.com.</p>
  
  <p>We added a method account() to our User model:</p>
  
  <pre><code>/**
   * Get the account the user is currently logged in to
   */
  public function account()
  {
      $server = explode('.', Request::server('HTTP_HOST'));
      $subdomain = $server[0];
      return Account::where('subdomain', $subdomain)-&gt;first();
  }
  </code></pre>
  
  <p>The problem is that there is always an extra query when we now use something like this in our view or controller:</p>
  
  <pre><code>Auth::user()-&gt;account()-&gt;accountname
  </code></pre>
  
  <p>When we want to get "Products" related to the account, we could use:</p>
  
  <pre><code>$products = Product::where('account_id', Auth::user()-&gt;account()-&gt;id)-&gt;get();
  </code></pre>
  
  <p>And yet again an extra query...</p>
  
  <p>Somehow we need to extend the Auth::user() object, so that the account data is always in there... or perhaps we could create a new Auth::account() object, and get the data there..</p>
  
  <p>What's the best solution for this?
  Thanks in advance</p>