2

User と Child の 2 つのモデルがあります。

class User extends Model {
  public function children() {
    return $this->belongsToMany('App\Child', 'user_child')->withPivot('relation_id');
  }
  public function connections() {
    // How to get the distinctly aggregate of my children.friends.contacts as a relationship here?
  }
}

class Child extends Model {
  public function contacts() {
    return $this->belongsToMany('App\User', 'user_child')->withPivot('relation_id');
  }
  public function friends() {
    return $this->belongsToMany('App\Child', 'child_connection', 'child_id1', 'child_id2');
  }
}

子供の友達の連絡先(ユーザー)である「つながり」と名付けた遠い関係を熱心にロードしたいと思います。

$user = User::with('children', 'children.friends', 'connections');

これをエレガントに行う方法はありますか?

ありがとうございました!

4

1 に答える 1