title: Select specific column from morph relation according to type in Laravel
body: <p>I am trying to write a query that selects columns from a model then selects some columns from a morph relationship table. But I have no idea to select columns, and relation tables have different columns. So some column has no slug, some have.</p>
  <pre><code>public function index()
  {
      $menus = Menu::whereActive(true)
          -&gt;with([
              'menuable' =&gt; function ($q) {
                  // This gives error if  there is no relation Pages model
                  $q-&gt;whereActive(true)-&gt;select('pages.id', 'pages.slug');
  
                  // Below not working
                  // if($q-&gt;type === Page::class){
                  //    $q-&gt;whereActive(true)-&gt;select('pages.id', 'pages.slug');
                  // } else if($q-&gt;type === Category::class){
                  //     $q-&gt;whereActive(true)-&gt;select('categories.id', 
                             'categories.slug');
                  // }
              }
          ])
          -&gt;get(['id', 'menuable_id', 'menuable_type', 'name']);
  
      $response = [
          'menus' =&gt; $menus,
      ];
  
      return $this-&gt;sendResponse($response);
  }
  </code></pre>
  <p><strong>Models</strong></p>
  <pre><code>class Menu extends Model
  {
      public function menuable()
      {
          return $this-&gt;morphTo();
      }
  }
  
  class Page extends Model
  {
      public function menu()
      {
          return $this-&gt;morphOne(Menu::class, 'menuable');
      }
  }
  
  class Category extends Model
  {
      public function menu()
      {
          return $this-&gt;morphOne(Menu::class, 'menuable');
      }
  }
  </code></pre>
  <p>How can I select specific columns from morph relation with checking morph type? I am using Laravel version 8.</p>