Laravel 4: Join tables from different database
join, laravel, laravel-4, mysql, php
Solution
You can do exactly that using the DB class:
$results = DB::select('select * from database1.users u1 LEFT JOIN database2.users u2 ON u1.id = u2.id WHERE u2.id = ?', array(5));
You can also use Fluent to build the query, which would look something like:
$users = DB::table('db1.users as db1')
->select('db1.*')
->leftJoin('db2.users as db2', 'db1.id', '=', 'db2.id')
->where('db2.id', 5)
->get();
Problem
I have a project that connects with different database, and i want to join those tables from different database using laravel 4. I searched already about this issue but i can't find the right answer. Is it possible to join tables from different database in laravel 4? If possible,does anyone can help me how to build a query for that?