ContatosAssociadosExport.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Exports;
  3. use App\Enums\UserTypeEnum;
  4. use App\Models\User;
  5. use Maatwebsite\Excel\Concerns\FromCollection;
  6. use Maatwebsite\Excel\Concerns\WithHeadings;
  7. use Maatwebsite\Excel\Concerns\WithStyles;
  8. use Maatwebsite\Excel\Concerns\WithColumnWidths;
  9. use Maatwebsite\Excel\Concerns\WithTitle;
  10. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  11. use PhpOffice\PhpSpreadsheet\Style\Fill;
  12. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  13. use Illuminate\Support\Collection;
  14. class ContatosAssociadosExport implements FromCollection, WithHeadings, WithStyles, WithColumnWidths, WithTitle
  15. {
  16. public function collection(): Collection
  17. {
  18. return User::where('type', UserTypeEnum::ASSOCIADO)
  19. ->orderBy('name', 'asc')
  20. ->get()
  21. ->map(fn($u) => [
  22. $u->name,
  23. $u->phone ?? '',
  24. $u->email ?? '',
  25. ]);
  26. }
  27. public function headings(): array
  28. {
  29. return ['Nome', 'Telefone', 'E-mail'];
  30. }
  31. public function title(): string
  32. {
  33. return 'Contatos';
  34. }
  35. public function columnWidths(): array
  36. {
  37. return ['A' => 40, 'B' => 22, 'C' => 35];
  38. }
  39. public function styles(Worksheet $sheet): array
  40. {
  41. return [
  42. 1 => [
  43. 'font' => ['bold' => true, 'color' => ['argb' => 'FFFFFFFF']],
  44. 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF661D75']],
  45. 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
  46. ],
  47. ];
  48. }
  49. }