Closed buglinjo closed 4 years ago
It's possible with a pivot model and a table alias:
class User extends Model
{
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function users()
{
return $this->hasManyDeep(
User::class,
[BranchUserPivot::class, Branch::class, BranchUserPivot::class.' as alias']
)->select('users.*');
}
}
class BranchUserPivot extends \Illuminate\Database\Eloquent\Relations\Pivot
{
use \Staudenmeir\EloquentHasManyDeep\HasTableAlias;
protected $table = 'branches_users';
}
Worked perfectly, thank you!
I'm having trouble writing hasManyDeep relationship.
I want to create a relationship which will return
User
's relatedUser
s through many to many relationship withBranch
.User
->branches_users
->Branch
->branches_users
->User
My current code:
It is generating incorrect SQL. Generated SQL:
It should generate something like this: