As far as I know joins will only work if it is in the same database, right?
Feb 4, 2019
3
Level 14
How could I join 2 collections from 2 different databases?
I have 2 tables in 2 different databases - users and posts. I want to retrieve all users AND all user's posts (count) in ONE collection. So that the end result would look like this.
$model->username // john
$model->fullname // John Smith
$model->user_avatar // jsm2m.jpg
$model->user_posts_count // 3 <-- from different database
Of course I could first retrieve all users and then in another collection get all his posts count like this...
// I don't want 2 different collection like this....
$users = Users::all();
$user_posts_count = Posts::where('user_id', 1)->count();
But I want it all to be in one collection (variable) for convenience.
Users table
id | username | fullname | user_avatar
1 john John Smith jsm2m.jpg
2 martin Bob Martin jk3i302.jpg
Posts table (different database)
id | user_id | post_body
1 1 hello world
2 1 howdy yall
3 1 what is up?
Please or to participate in this conversation.