我正在try 创建一个模型,并在Laravel 4.2中迁移该模型.我所有的Laravel应用程序都使用同一个名为laravel
的MySQL数据库.然而,我们还有另一个数据库(在同一台服务器上),名为main_db
,其中包含一个users
表,我想用它作为laravel
数据库中我自己的laravel_users
表中一些外键的来源.
根据Laravel文档,我会用以下代码指定一个外键:
$table->foreign('user_id')->references('id')->on('users');
但我相信这是假设'users'
表存在于同一个数据库中.
Is it possible to do trans-database foreign keys in Laravel? Would I have to first create a model that uses the users
table from main_db
? And is it possible to set up two different database connections in the app/config/database.php
?