i have two tables: Users and Followers.
user
id, username
1, foo
2, bar
3, test
followers
id, user_id_follows, user_id_followed
1, 2, 1
2, 3, 1
Which means that the users "bar" and "test" follow the user "foo".
I would like to have a result-set like:
[
id: "foo",
username: "bar",
followers: ["bar", "test"]
]
Alternatively as JSON object. Is this possible with eloquent ORM? user has a hasMany-relationship to follower and follower belongsTo user. Is it possible to get the relations but only the usernames of the followers? I also tried to do this via raw-sql query. But using DB::select(DB::raw($query)); gets me an non-multidimensional object which means that "followers" only has "bar" and not both followers.
So what is the best way to get a multidimensional result-set? Can i still rely on eloquentORM? How?
Thank you and best regards
Phil