| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Exports;
- use App\Enums\UserTypeEnum;
- use App\Models\User;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithStyles;
- use Maatwebsite\Excel\Concerns\WithColumnWidths;
- use Maatwebsite\Excel\Concerns\WithTitle;
- use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use Illuminate\Support\Collection;
- class ContatosAssociadosExport implements FromCollection, WithHeadings, WithStyles, WithColumnWidths, WithTitle
- {
- public function collection(): Collection
- {
- return User::where('type', UserTypeEnum::ASSOCIADO)
- ->orderBy('name', 'asc')
- ->get()
- ->map(fn($u) => [
- $u->name,
- $u->phone ?? '',
- $u->email ?? '',
- ]);
- }
- public function headings(): array
- {
- return ['Nome', 'Telefone', 'E-mail'];
- }
- public function title(): string
- {
- return 'Contatos';
- }
- public function columnWidths(): array
- {
- return ['A' => 40, 'B' => 22, 'C' => 35];
- }
- public function styles(Worksheet $sheet): array
- {
- return [
- 1 => [
- 'font' => ['bold' => true, 'color' => ['argb' => 'FFFFFFFF']],
- 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF661D75']],
- 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
- ],
- ];
- }
- }
|