title: Retrieving data and relationships for JSON output
body: <p>I'm new to all of this and trying to wrap my head around Laravel. I have two models setup and one pivot table. I'm trying to output some JSON in the following format:</p>
  
  <pre><code>[
      {
          "question": "somequestiongoeshere",
          "tags": [
              "tag1",
              "tag2"
          ]
      },
      {
          "question": "somequestiongoeshere",
          "tags": [
              "tag1",
              "tag2"
          ]
      }
  ]
  </code></pre>
  
  <p>I've only been able to output either tags or questions but not in the format above. Any guidance would greatly be appreciated.</p>
  
  <p>Question.php</p>
  
  <pre><code>&lt;?php namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Question extends Model {
  
      public function tags() {
          return $this-&gt;hasMany('App\Tag');
      }
  
  }
  </code></pre>
  
  <p>Tag.php</p>
  
  <pre><code>&lt;?php namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Tag extends Model {
  
      public function questions() {
          return $this-&gt;hasMany('App\Question');
      }
  
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>public function index() {
      return Question::all();
  }
  </code></pre>