I have already defined my connections in database.php :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db1'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
...
],
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST_2', '127.0.0.1'),
'port' => env('DB_PORT_2', '3306'),
'database' => env('DB_DATABASE_2', 'db2'),
'username' => env('DB_USERNAME_2', 'root'),
'password' => env('DB_PASSWORD_2', ''),
...
],
I want to join table user from db2 with table ticket from db1.Please help is appreciated.I tried the one below but since ticket table is from db1 is not recognized
$user= DB::connection("mysql2")->table('User')
->join('ticket', 'User.Id', '=','ticket.user_id')
->select('User.*')
->where('ticket.id', '=', 1)
->get();
Thanks in advance