FormExport.php 674 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Exports;
  3. use App\Exports\Sheets\FormAnswerSheet;
  4. use App\Models\Fpdx\FormQuestionModel;
  5. use Maatwebsite\Excel\Concerns\Exportable;
  6. use Maatwebsite\Excel\Concerns\WithMultipleSheets;
  7. class FormExport implements WithMultipleSheets
  8. {
  9. use Exportable;
  10. private $formId;
  11. public function __construct($formId)
  12. {
  13. $this->formId = $formId;
  14. }
  15. public function sheets(): array
  16. {
  17. $sheets = [];
  18. $questions = FormQuestionModel::where('form_id', $this->formId)->get();
  19. foreach ($questions as $question) {
  20. $sheets[] = new FormAnswerSheet($question);
  21. }
  22. return $sheets;
  23. }
  24. }