title: Laravel querying polymorphic relationships with nested many to many items
body: <p>I have 4 tables with the following relationships:</p>
  
  <pre><code>class Note extends Model
  {
      public function noteable() {
          return $this-&gt;morphTo();
      }
  }
  
  class Expense extends Model
  {
      public function notes()
      {
          return $this-&gt;morphMany(Note::class, 'noteable');
      }
  }
  
  class Review extends Model
  {
      public function notes()
      {
          return $this-&gt;morphMany(Note::class, 'noteable');
      }
  
      public function repairs()
      {
          return $this-&gt;belongsToMany(Repair::class);
      }
  
  }
  
  class Repair extends Model
  {
      public function reviews()
      {
          return $this-&gt;belongsToMany(Review::class);
      }
  }
  </code></pre>
  
  <p>as you can see Note is in the relationship one to many polymorphic and Reviews is in many to many with Repairs.</p>
  
  <p><strong>I would like to take all Notes that Reviews also has Repairs. How do I do such an operation?</strong></p>
  
  <p>Following the <a href="https://laravel.com/docs/6.x/eloquent-relationships#querying-polymorphic-relationships" rel="nofollow noreferrer">documentation</a> I am trying to do something like this:</p>
  
  <pre><code>    $notes = App\Note::query()
          -&gt;with(['noteable' =&gt; function (MorphTo $morphTo) {
              $morphTo-&gt;morphWith([
                  Review::class =&gt; ['repairs']
              ]);
      }])-&gt;get();
  </code></pre>
  
  <p>I would like to my query should return something like:</p>
  
  <pre><code>[
  
      {
          "id": 11,
          "noteable_id": 4,
          "noteable_type": "App\\Expense",
          "noteable": {
               "id": 4,
               "name": "Expense",
               "category": "general"
          }
      },
      {
          "id": 13,
          "noteable_id": 5,
          "noteable_type": "App\\Review",
          "noteable": {
               "id": 5,
               "name": "Review 5",
               "mileage": 120000,
               "repairs": [..., ...] //what I need
          }
      }
  
  ]
  </code></pre>