title: Laravel 4.x Alias a table using Eloquent while performing a join
body: <p>I'm aware that in my Model I can alias my table like so:</p>
  
  <pre><code>protected $table = 'territories_sign_in_out AS tsio';
  </code></pre>
  
  <p>so that I can still use Eloquent to build collections but what about when I need to use the table in a join like this:</p>
  
  <pre><code>Territories::select('territories.id', 'tsio.signed_out')
             -&gt;join('territories_sign_in_out', function($join) use ($id)
             {
                 //
             })
             -&gt;get();
  </code></pre>
  
  <p>Right now I get an error:</p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error 
  in your SQL syntax; check the manual that corresponds to your MySQL server 
  version for the right syntax to use near 'as `tsio`.`publisher_id` = ? order 
  by `territory_id` asc, `signed_in` asc' at line 1 (SQL: select * from 
  `territories_sign_in_out` as `tsio` where `territories_sign_in_out` as 
  `tsio`.`publisher_id` = 59 order by `territory_id` asc, `signed_in` asc)
  </code></pre>
  
  <p>Am I stuck just using Fluent?</p>
  
  <pre><code>DB::table('territories_sign_in_out AS tsio')...
  </code></pre>
  
  <p>I would like to also be able to build statements using <code>Eloquent</code> like this:</p>
  
  <pre><code>TerritoriesSignInOut::select('t.id', 't.label', 'tsio.signed_out', 'tsio.publisher_id')
                      -&gt;join('territories AS t', 'tsio.territory_id', '=', 't.id')
                      -&gt;whereNull('tsio.signed_in')
                      -&gt;orderBy('t.label', 'ASC')
                      -&gt;get();
  </code></pre>
  
  <p>and I can only do this by adding <code>as tsio</code> like I mentioned at the fore of this question.</p>
  
  <p>To clarify table <code>territories</code> = model <code>Territories</code>. Table <code>territories_sign_in_out</code> = model <code>TerritoriesSignInOut</code>.</p>