title: Query multiple, nested Relationships in Laravel/Eloquent
body: <p>I'm trying to build a simple news feed for posts in Laravel with Eloquent.</p>
  
  <p>I basically want to retrieve all <strong>Posts</strong>...</p>
  
  <ul>
  <li>where I am author</li>
  <li>where people I follow are author (followable)</li>
  <li>where people I follow have commented on</li>
  <li>where people with same field_id are author</li>
  <li>where poeple with same school_id are author</li>
  </ul>
  
  <p>in one query.</p>
  
  <p>As I never worked intensivly with joined/combined SQL queries, any help on this is greatly appreciated!</p>
  
  <h2>My Tables</h2>
  
  <p><code>users</code> table</p>
  
  <pre><code>+----+
  | id |
  +----+
  </code></pre>
  
  <p><code>posts</code> table</p>
  
  <pre><code>+----+-----------+-------------+
  | id | author_id | author_type |
  |----|-----------|-------------|
  |    | users.id  | 'App\User'  |
  +----+-----------+-------------+
  </code></pre>
  
  <p><code>comments</code> table</p>
  
  <pre><code>+----+----------------+------------------+-----------+-------------+
  | id | commentable_id | commentable_type | author_id | author_type |
  |----|----------------|------------------|-----------|-------------|
  |    | posts.id       | 'App\Post'       | users.id  | 'App\User'  |
  +----+----------------+------------------+-----------+-------------+
  </code></pre>
  
  <p><code>schoolables</code> table</p>
  
  <pre><code>+---------+-----------+----------+
  | user_id | school_id | field_id |
  +---------+-----------+----------+
  </code></pre>
  
  <p><code>followables</code> table</p>
  
  <pre><code>+-------------+---------------+---------------+-----------------+
  | follower_id | follower_type | followable_id | followable_type |
  |-------------|---------------|---------------|-----------------|
  | users.id    | 'App\User'    | users.id      | 'App\User'      |
  +-------------+---------------+---------------+-----------------+
  </code></pre>
  
  <h2>My Models</h2>
  
  <pre><code>class Post extends Model
  {
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphTo
       */
      public function author()
      {
          return $this-&gt;morphTo();
      }
  
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphMany
       */
      public function comments()
      {
          return $this-&gt;morphMany(Comment::class, 'commentable');
      }
  }
  
  class Comment extends Model
  {
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphTo
       */
      public function author()
      {
          return $this-&gt;morphTo();
      }
  
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphTo
       */
      public function commentable()
      {
          return $this-&gt;morphTo();
      }
  }
  
  class User extends Model
  {
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphMany
       */
      public function posts()
      {
          return $this-&gt;morphMany(Post::class, 'author')-&gt;orderBy('created_at', 'desc');
      }
  
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphMany
       */
      public function comments()
      {
          return $this-&gt;morphMany(Comment::class, 'author')-&gt;orderBy('created_at', 'desc');
      }
  
      /**
       * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
       */
      public function schoolables()
      {
          return $this-&gt;hasMany(Schoolable::class);
      }
  
      /**
       * @return \Illuminate\Database\Eloquent\Relations\MorphMany
       */
      public function following()
      {
          return $this-&gt;morphMany(Followable::class, 'follower');
      }
  }
  </code></pre>