SingleSheetExport.php 584 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Exports;
  3. use Maatwebsite\Excel\Concerns\FromCollection;
  4. use Maatwebsite\Excel\Concerns\WithTitle;
  5. use Illuminate\Support\Collection;
  6. class SingleSheetExport implements FromCollection,WithTitle
  7. {
  8. protected $data;
  9. protected $sheetName;
  10. public function __construct(array $data, string $sheetName)
  11. {
  12. $this->data = $data;
  13. $this->sheetName = $sheetName;
  14. }
  15. public function collection()
  16. {
  17. return new Collection($this->data);
  18. }
  19. public function title(): string
  20. {
  21. return $this->sheetName;
  22. }
  23. }