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

网友答案:

Found a much better way. What we will do is create a many to many relationship with the users table to the users table and use your followers table as the pivot table. I've also done some extra work so you can view both followeds and followers for a user.

Unfortunately, the way you have your tables setup didn't make a lot of sense to me, so my followers table looks like id, user_id, follow_id. This way, I can easily find who a user is following by looking up that user's id in the user_id column and I can see who that user is followed by, by looking up his user_id in the follow_id column. Maybe this is what you meant with your table, in which case, you could just drop in the column names you have. With that in mind, here is what I did.