title: Laravel Eloquent relationship data hidden in response
body: <p>I have two models: <code>User</code> and <code>Group</code>. A <code>user</code> can be a member of just one <code>group</code>, and a <code>group</code> can have multiple <code>users</code>:</p>
  
  <p><strong>User:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class User extends Model
  {
      protected $table = 'user';
      protected $primaryKey = 'user_id';
  
      protected $fillable = [];
      protected $visible = ['user_id', 'name', 'points', 'group_id', 'profile'];
  
  
      /**
       * Get group where user belongs to
       */
      public function group()
      {
          return $this-&gt;belongsTo('App\Models\Group', 'group_id', 'group_id');
      }
  }
  </code></pre>
  
  <p><strong>Group:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Group extends Model
  {
      protected $table = 'group';
      protected $primaryKey = 'group_id';
  
      protected $fillable = [];
      protected $visible = ['group_id', 'name', 'profile'];
  
      /**
       * Get all group users.
       */
      public function users()
      {
          return $this-&gt;hasMany('App\Models\User', 'group_id', 'group_id');
      }
  }
  </code></pre>
  
  <p>Now in my controller, I want to retrieve the user data and the users' group data. Therefore I use this:</p>
  
  <pre><code>$users = User::with('group')
          -&gt;orderBy('points', 'DESC')
          -&gt;take(50)
          -&gt;get();
  
  return response()-&gt;json($users);
  </code></pre>
  
  <p>So far so good. I expect the above to return something like this:</p>
  
  <pre><code>[
    {
      "user_id": 27,
      "name": "linnie15",
      "points": 18565,
      "group_id": 6,
      "profile": null,
      "group": {
        "group_id": 6,
        "name": "White Wall",
        "profile": "Et tempore voluptatibus sunt ratione ut. Eum sint mollitia omnis eius ut facilis aut. Sed quisquam quis velit qui sint soluta. Autem quia ipsam esse sapiente delectus vel."
      }
    },
  ]
  </code></pre>
  
  <p>But, here is the problem. The only thing it returns is this:</p>
  
  <pre><code>[
    {
      "user_id": 27,
      "name": "linnie15",
      "points": 18565,
      "group_id": 6,
      "profile": null
    },
  ]
  </code></pre>
  
  <p>How is that possible? In fact, I found the solution, by adding <code>'group'</code> to the <code>$visible</code> array in the <code>User</code> model. But why is that? I mean, should I really add all my relationships to the <code>$visible</code> array? Why would that be necessary. If you query a relationship, you always want the result, isn't it?</p>