title: Is it possible to reference a Foreign Key in a different database in Laravel?
body: <p>I'm trying to create a model and a migration for that model in Laravel 4.2. All of my Laravel apps use the same MySQL database called <code>laravel</code>. However, we also have another database (on the same server), called <code>main_db</code> that contains a <code>users</code> table, which I would like to use for the source of a few foreign keys in my own <code>laravel_users</code> table in the <code>laravel</code> database.</p>
  
  <p>According to the Laravel documentation, I would designate a foreign key with this code:</p>
  
  <pre><code>$table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
  </code></pre>
  
  <p>But I believe this assumes that the <code>'users'</code> table exists within the same database.</p>
  
  <p>Is it possible to do trans-database foreign keys in Laravel? Would I have to first create a model that uses the <code>users</code> table from <code>main_db</code>? And is it possible to set up two different database connections in the <code>app/config/database.php</code>?</p>