I am using two database connections in my Laravel project.
I need to modify tables in both databases.
I have set up everything and now I am playing around and trying to get data from the first and the second database, but the docs hardly give information on how to do so, I only found this:
$users = DB::connection('foo')->select(...);
Are there more resources somewhere? I was not able to find anything.
So far I understand that I cant use eloquent anymore if I use multiple databases? At least I cant use eloquent for the second database, which is not default.
For testing, I have created the same tables on both databases with different data. But I cant query the data, I always get this error:
Undefined property: Illuminate\Database\MySqlConnection::$User
Here are my tests:
$users1 = DB::connection('mysql_live')->select('SELECT * FROM users');
info($users1);
$users2 = DB::connection('mysql')->User::all();
info($users2);
I also tried:
$users1 = DB::connection('mysql_live')->User::all();
Best would be documentation on how to correctly use DB::connection
and actually select, edit, insert data, etc.
EDIT
- How do I actually f.e. select all users from both databases?
- For the second database, I will never need to create new columns or tables, I will only need to update data, probably eloquent is not needed there, which means I always need to execute raw SQL, correct? If I use eloquent I need to create the models as well?