FromUsersQueryExportWithMapping.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Maatwebsite\Excel\Tests\Data\Stubs;
  3. use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
  4. use Illuminate\Database\Eloquent\Relations\Relation;
  5. use Illuminate\Database\Query\Builder;
  6. use Maatwebsite\Excel\Concerns\Exportable;
  7. use Maatwebsite\Excel\Concerns\FromQuery;
  8. use Maatwebsite\Excel\Concerns\WithEvents;
  9. use Maatwebsite\Excel\Concerns\WithMapping;
  10. use Maatwebsite\Excel\Events\BeforeSheet;
  11. use Maatwebsite\Excel\Tests\Data\Stubs\Database\User;
  12. class FromUsersQueryExportWithMapping implements FromQuery, WithMapping, WithEvents
  13. {
  14. use Exportable;
  15. /**
  16. * @return Builder|EloquentBuilder|Relation
  17. */
  18. public function query()
  19. {
  20. return User::query();
  21. }
  22. /**
  23. * @return array
  24. */
  25. public function registerEvents(): array
  26. {
  27. return [
  28. BeforeSheet::class => function (BeforeSheet $event) {
  29. $event->sheet->chunkSize(10);
  30. },
  31. ];
  32. }
  33. /**
  34. * @param User $row
  35. * @return array
  36. */
  37. public function map($row): array
  38. {
  39. return [
  40. 'name' => $row->name,
  41. ];
  42. }
  43. }