title: Laravel eloquent - prevent overriding values when joining tables
body: <h2>Ok, so i have following two models: <code>Account</code> and  <code>Role</code></h2>
  
  <pre><code>class Account extends Eloquent
  {
    protected $table = 'account';
  
    /* [...] */
  
    public function group() {
      return $this-&gt;belongsTo('Group');
    }
  }
  </code></pre>
  
  <h2>and</h2>
  
  <pre><code>class Role extends Eloquent {
  
    protected $table = 'role';
  
    public function accounts() {
      return $this-&gt;hasMany('Account');
    }
  
  }
  </code></pre>
  
  <h2>and database tables: <code>account</code> and <code>role</code></h2>
  
  <pre><code>account
  -------
  id
  name
  role_id (nullable)
  
  role
  ----
  id
  name
  </code></pre>
  
  <h2>And now the thing is:</h2>
  
  <p>I need to order <code>accounts</code> by <code>role.name</code> column. But after join (or leftJoin) values are overriden by those from second table. Here's some code:</p>
  
  <pre><code>$response = Account::with('role')-&gt;leftJoin('group', 'group.id', '=', 'account.group_id')-&gt;get();
  </code></pre>
  
  <p>After that values for <code>id</code> and <code>name</code> are incorrect in eloquent collections.</p>
  
  <p>Also, i need the return to be eloquent type models as i'm returning back the response in JSON, where it is important that later in JS (after parsing JSON) i can do just <code>account.role.name</code>.</p>
  
  <p>Changing names of fields in tables (like: id -> account_id, and: id -> role_id) would be an workaround, but that's not my case - need to have primary key named <code>id</code> for every table.</p>
  
  <p>[edit]
  Yep, so the question is simply: how to solve that problem?</p>