WithMappingExport.php 741 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Illuminate\Support\Collection;
  4. use Maatwebsite\Excel\Concerns\Exportable;
  5. use Maatwebsite\Excel\Concerns\FromCollection;
  6. use Maatwebsite\Excel\Concerns\WithMapping;
  7. class WithMappingExport implements FromCollection, WithMapping
  8. {
  9. use Exportable;
  10. /**
  11. * @return Collection
  12. */
  13. public function collection()
  14. {
  15. return collect([
  16. ['A1', 'B1', 'C1'],
  17. ['A2', 'B2', 'C2'],
  18. ]);
  19. }
  20. /**
  21. * @param mixed $row
  22. * @return array
  23. */
  24. public function map($row): array
  25. {
  26. return [
  27. 'mapped-' . $row[0],
  28. 'mapped-' . $row[1],
  29. 'mapped-' . $row[2],
  30. ];
  31. }
  32. }