php - Laravel Eloquent - Table join -


i have 1 problem need help. i'm doing 1 project in learning purposes.

i have 2 tables, first 1

users contain id (pk, ai), username, email, password , on...

another table called

friends

contain user_a (fk users.id), user_b (fk users.id), status (0 - pending, 1 - confirmed)...

lets current logged user have id 1.

i need join 2 tables , complete friend list logged user, query trough table friends user_a or user_b = logged user id, , data (from table users) friend... lets this:

user_a = 1, user_b = 2 userb_a = 3, user_b = 1

i need info users 2, 3.

i hope understand need.

btw know how without using eloquent, need use eloquent.

thanks lot!

this many many relationship, need belongstomany.

// basic setup public function friends() {     return $this->belongstomany('user', 'friends', 'user_a', 'user_b')       ->withpivot('confirmed'); } 

however that's not all, since want bidirectional. means need setup 2 relationships - here can find exact solution this:

friendship system laravel : many many relationship


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -