title: Eloquent eager loading does not return related model data
body: <p>In my Laravel project I have two Eloquent Models <code>Set</code> and <code>Card</code>, they have one to many relationship between them. <code>Set</code> has many <code>Cards</code> and <code>Cards</code> belong to <code>Set</code>. </p>
  
  <p>I'm trying to pull the data using Eloquent Eager Loading using the <code>with()</code> function. But for some reason the <code>cards</code> array inside <code>sets</code> is returning as blank <code>[]</code>.</p>
  
  <p><strong>Set.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App;
  use App\Card;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Set extends Model
  {
      protected $table = "sets";
  
      public function cards() {
          return $this-&gt;hasMany('App\Card');
      }
  }
  
  </code></pre>
  
  <p><strong>Card.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use App\Set;
  use Illuminate\Database\Eloquent\Model;
  
  class Card extends Model
  {
      protected $table = "cards";
  
      public function sets() {
          return $this-&gt;belongsTo('App\Set');
      }
  }
  
  </code></pre>
  
  <p><strong>Controller code</strong></p>
  
  <pre><code>$sets = Set::with([
           'cards' =&gt; function($query){
           $query-&gt;select('name', 'description');
           },
         ])-&gt;get();
  
    return $sets;
  
  </code></pre>
  
  <p><code>name</code> and <code>description</code> are the fields that I have in <code>Cards</code> table except of the primary key and foreign key.</p>
  
  <p>It returns with <code>"cards": []</code> in my <code>JSON</code> array of <code>sets</code>.</p>
  
  <p>I have tried using below code in controller,</p>
  
  <pre><code>$sets = Set::with('cards.*')-&gt;get();
  
  return $sets;
  
  </code></pre>
  
  <p>Did not work.</p>
  
  <p>Tried adding the foreign key (set_id which is in the Cards table)  in the <code>hasMany</code> method in my <code>Set</code> model that creates relationship with <code>Cards</code> table. But of no result.</p>
  
  <p>To be mentioned, when I tried pulling the data from <code>Cards</code> table separately from my <code>CardController</code>, it returned all <code>Cards</code> data. </p>
  
  <p>Some clue would mean great help. Thank you for your time.</p>