LoginSignup
1
1

More than 3 years have passed since last update.

【Laravel】whereHasでリレーションのネスト先を検索条件として指定する方法。

Posted at

自分用のメモとして残します。

リレーションのネスト先。
言い方を変えるとリレーション先のリレーション?のフィールドをwhereHasで検索する方法です。

■やり方

リレーションの定義は割愛させていただきます。
withと同じようにピリオドでリレーションのチェーンをします。

$query->whereHas('user.phone', function($query) use($cond) {
    $query->where('phonename', $cond['phonename']);
});

 

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1