Hi, I had been searching for the solution in the internet for a long time but still I couldn't find the solution, most of the search results is joining on different tables in single database.
I need the solution for different DB::Connection left join and get the query results.
Please noted that I only want to view the results only, no any CRUD required.
Moreover, all databases are within the same server, if using single connection like DB::connection('sqlsrv') or ('sqlsrv2') can get the result easily only when join is having issues.
Below are my codes so far.
<?php
namespace App\Http\Controllers;
use App\UserInfo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class UserInfoController extends Controller
{
public function index()
{
// $UserInfos = DB::connection('sqlsrv2')->select('select * from TMS_CLOCKING');
// $userinfos = DB::connection('sqlsrv')->select('select * from userinfo');
// $userinfos = DB::table('USERINFO')->where('USERID', '=', '252')->get();
// $userinfos = DB::table('CHECKINOUT')
// ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
// ->where('USERINFO.CardNo', '=', '1411078')
// ->get();
// $db = DB::connection('sqlsrv2');
$employee_profile =
DB::connection('sqlsrv2')
->table('EMPLOYEE')
->where('ISACTIVE', '=', 'Y')
->where('CARDID', '!=', '')
->where('DEPARTMENT', '!=', '')
->get();
// $employee_attendance =
// DB::table('CHECKINOUT')
// ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
// ->leftJoin('TMS_EMPLOYEE', 'USERINFO.CardNo', '=', 'TMS_EMPLOYEE.CardID')
// ->get();
// $db = DB::Connection('sqlsrv2')->('EMPLOYEE');
// $employee_attendance =
// DB::table('CHECKINOUT')
// ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
// ->leftjoin($db, 'USERINFO.CardNo', '=', 'EMPLOYEE.CARDID')
// ->get();
$employee_attendance =
DB::Connection('sqlsrv')
->table('CHECKINOUT')
->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
->leftjoin(DB::Connection('sqlsrv2'))
->table('EMPLOYEE', 'USERINFO.CardNo', '=', 'EMPLOYEE.CardID')
->get();
$employee_attendance =
DB::table(DB::raw('EMPLOYEE'))
// $userinfos = $employee_profile;
$userinfos = $employee_attendance;
return view('userinfo.index', ['userinfos' => $userinfos]);
}
}