Laravel - How to join 2 tables from different db connection? Laravel - How to join 2 tables from different db connection? laravel laravel

Laravel - How to join 2 tables from different db connection?


Try to remove the connection('phc') and prefix the php tables as you do with mysql tables.You are choosing the connection, so the query builder should understand that it would prefix your tables with the connection names. So, when you type 'mysql.cart' the query builder will do 'phc.mysql.cart'.

$artigos = DB::table('phc.st')        ->join('mysql.cart', 'mysql.cart.id_item', '=', 'phc.st.ststamp')        ->select('phc.st.ststamp', 'phc.st.ref', 'phc.st.design', 'phc.st.imagem', 'mysql.cart.qtt')        ->where('mysql.carts.id_user','=',Auth::id())        ->paginate(10);


this is my code for joining two table:

$departmetns = DB::table('department')      ->select('department.*', 'faculty.name as f_name')      ->join('faculty','department.faculty_id', '=' ,'faculty.id')       ->get();

in your case

USE DB;DB::table('st')    ->select('st.ststamp', 'st.ref', 'st.design', 'st.imagem', 'cart.qtt')    ->join('cart', 'st.ststamp', '=', 'cart.id_item')    ->where('carts.id_user','=',Auth::id())    ->paginate(10);