title: How to map one to many relationships with Laravel excel 3.1 as a row
body: <p>I have followed the document <a href="https://laravel-excel.maatwebsite.nl/3.0/exports/mapping.html" rel="nofollow noreferrer">maatwebsite</a> version 3.1 and I'm struggling with mapping all question choices into a row with a question when export as excel.
  Here's what I did in App\Exports\QuestionExcel.php:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Exports;
  
  use App\Question as Question;
  use Maatwebsite\Excel\Concerns\FromCollection;
  use Maatwebsite\Excel\Concerns\FromQuery;
  use Maatwebsite\Excel\Concerns\WithHeadings;
  use Maatwebsite\Excel\Concerns\Exportable;
  use Maatwebsite\Excel\Concerns\WithMapping;
  
  class QuestionExcel implements FromCollection, WithHeadings, WithMapping
  {
      use Exportable;
      /*
          Question $question
      */
      private $i = 1;
  
      public function collection()
      {
          return Question::with('level','questionType','questionChoices')-&gt;get();
      }
  
      public function map($question): array
      {
          // $question 
  
          return [
              $this-&gt;i++,
              $question-&gt;description,
              $question-&gt;questionType-&gt;name,
              $question-&gt;level-&gt;name,
              $question-&gt;duration,
              $question-&gt;questionChoices-&gt;map(function ($choice){
                                return $choice-&gt;label;
                             }),
          ];
      }
  
  
      public function headings(): array
      {
          return [
              'No',
              'Question',
              'Type',
              'Level',
              'Duration (s)',
          ];
      }
  }
  </code></pre>
  
  <p>In App\Http\Controllers\ExcelController.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Maatwebsite\Excel\Excel;
  use App\Exports\QuestionExcel;
  use App\Level as Level;
  
  class ExcelController extends Controller
  {
      private $excel;
  
      public function __construct(Excel $excel)
      {
          $this-&gt;excel = $excel;
      }
  
      public function export_questions($level_id){
         $level = Level::find($level_id);
         $level_name = str_replace(' ', '_', $level-&gt;name);
         return (new QuestionExcel)-&gt;download($level_name.'_question_exports.xlsx');
      }
  }
  </code></pre>
  
  <p>The result
  <a href="https://i.stack.imgur.com/T8Srz.png" rel="nofollow noreferrer">The result of excel</a></p>
  
  <p>Please anyone help me to get result like this? 
  <a href="https://i.stack.imgur.com/LBOjz.png" rel="nofollow noreferrer">Expected result</a></p>