EloquentCollectionWithMappingExport.php 844 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Illuminate\Database\Eloquent\Collection;
  4. use Maatwebsite\Excel\Concerns\Exportable;
  5. use Maatwebsite\Excel\Concerns\FromCollection;
  6. use Maatwebsite\Excel\Concerns\WithMapping;
  7. use Maatwebsite\Excel\Tests\Data\Stubs\Database\User;
  8. class EloquentCollectionWithMappingExport implements FromCollection, WithMapping
  9. {
  10. use Exportable;
  11. /**
  12. * @return Collection
  13. */
  14. public function collection()
  15. {
  16. return collect([
  17. new User([
  18. 'firstname' => 'Patrick',
  19. 'lastname' => 'Brouwers',
  20. ]),
  21. ]);
  22. }
  23. /**
  24. * @param User $user
  25. * @return array
  26. */
  27. public function map($user): array
  28. {
  29. return [
  30. $user->firstname,
  31. $user->lastname,
  32. ];
  33. }
  34. }