I have an application that use 2 databases. I need to create a query that joins a table from one database with a table form another but I don't know how to do that.
So, I have a connection name mysql
and phc
. I can communicate with both with no problems.
Now, I'm trying to do this query:
$artigos = DB::connection('phc')->table('st')
->join('mysql.cart', 'mysql.cart.id_item', '=', 'st.ststamp')
->select('st.ststamp', 'st.ref', 'st.design', 'st.imagem', 'mysql.cart.qtt')
->where('mysql.carts.id_user','=',Auth::id())
->paginate(10);
But returns me : General error: 20018 Invalid object name 'mysql.cart'
I want to access connection mysql table cart and connection phc table st.
How can I solve this?
Thank you
use database_name
and work in this database, for work in other database you needuse other database_name2
and work this. I think yout need run directly query with out eloquen. for example see this question #11427429 – Immediacy