Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

I think this should work using Eager Load Contraints.

$users = User::with(array('friend_user' => function($query)
{
    $query->where('user_id', '=', '1');

}))->get();
Last updated 1 year ago.
0

Are you sure you want pivot table for this? It seems that single User can have only one other User that invited him, so basically this is 1-to-many relationship. Then you should have a nullable field on users table: user_id (or inviter_id or whatever u call it). This way you call relations on the same table which is a bit tricky in Eloquent, so leave a note if that would suit you.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

wkolcz wkolcz Joined 17 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.