I solved this problem by adding models of the "join" and "table" variables that define the database in which this model is stored.
For example, I have a model called "User" in a database called "core_database" in the user table. On the other hand, I have a model named "UserEvents" in the database named "logs_database" in the table "user_events"
Therefore, I will have two connections in the config / database.php file:
'core_db_connection' => [ 'driver' => 'mysql', 'host' => host_ip, 'port' => port, 'database' => 'core_database', 'username' => username, 'password' => password, .... ], 'logs_db_connection' => [ 'driver' => 'mysql', 'host' => host_ip, 'port' => port, 'database' => 'logs_database', 'username' => username, 'password' => password, .... ],
And the models will be similar:
class User extends Authenticatable { protected $table = 'core_database.users'; protected $connection = 'core_db_connection'; ... } class UserEvents extends Model { protected $table = 'logs_database.user_events'; protected $connection = 'logs_db_connection'; ... }
This has been verified in databases on the same database server. Database connections have the same ip host. I have not tried another way
Using this configuration, I can make any query to two or more separate databases on the same database server, in my case, RDS.
I hope this helps you!