title: Assign an array of objects to another object's key in Laravel
body: <p>I am working on a Q&amp;A app in Laravel. Here, I have two migrations or database tables, one is question_bank and second is answer_choices. There is one to many relation between question and answers table. While retrieving a question, I want to retrieve all of the answers which are related with this question.  </p>
  
  <p>For this i wrote a method:</p>
  
  <pre><code>public function getQuestion($id){
      $question=QuestionBank::find($id);
      $answers=AnswerBank::where('question_id','=',$id)-&gt;get();
      $question-&gt;answers=$answers;
          return Response::json($question);
  }
  </code></pre>
  
  <p>The answer_choices migration is :  </p>
  
  <pre><code>class AnswerChoices extends Migration {
  public function up()
  {
  Schema::create('answer_choices', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;integer('question_id')-&gt;unsigned();
          $table-&gt;mediumtext('answer_text');
          $table-&gt;boolean('correct')-&gt;nullable();
          $table-&gt;foreign('question_id')-&gt;references('id')-&gt;on('question_bank');
      });
  }
  
  public function down()
  {
      Schema::drop('answer_choices');
  }
  }
  </code></pre>
  
  <p>And the model is :  </p>
  
  <pre><code>&lt;?php
  
  class AnswerBank extends \Eloquent {
  protected $fillable = [];
  protected $table = "answer_choices";
  }
  </code></pre>
  
  <p>Question model is </p>
  
  <pre><code>&lt;?php
  
  class QuestionBank extends \Eloquent {
  protected $fillable = [];
  protected $table = "question_bank";
  }
  </code></pre>
  
  <p>I expected i will get result as <code>question.answers:[{},{},{}]</code><br>
  but on client side I am getting it like <code>"question.answers":{}</code> as a blank object. When I return only <code>$answers</code>, it shows all the answer objects in the array like <code>[{},{},{]]</code>. </p>
  
  <p>How can I get the answers objects as an array of objects in JavaScript? </p>