title: Laravel Nested Query Builder Json Response
body: <p>I am trying to get a certain structure from a query builder which looks as:</p>
  
  <pre><code>{
    "status": "success",
    "data": {
      "id": 1,
      "email": "test@test.com",
      "birth_date": "1992-08-17",
      "gender": "M",
      "is_active": 1,
      "role": {
        "id": 1,
        "name": "Admin",
        "created_at": "2017-01-11 15:16:14",
        "updated_at": null
      }
    }
  }
  </code></pre>
  
  <p>As you can see, i need for the relationship to be nested, in this case User to Roles.</p>
  
  <p>I can get this structure using eager load with <code>User::with('role')</code>.</p>
  
  <p>I have this query but it returns everything in one column.
  Is there any way i can get this same structure using query builder?
  Is using eager load bad practice?</p>
  
  <pre><code>User::select('users.id', 'users.full_name')
      -&gt;join('roles as r', 'r.id', '=', 'users.role_id')
      -&gt;where('users.id', $user_id)
      -&gt;get();
  </code></pre>
  
  <p>Thanks in advance.</p>