JezK
Edit File: GridExport.php
<?php namespace App\Exports; use Illuminate\Support\Facades\DB; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\WithHeadings; use Carbon\Carbon as Carbon; class GridExport implements FromCollection, WithHeadings { use Exportable; public function headings(): array { return ['IDENTIFICADOR', 'PRODUCTO', 'CAMPANIA', 'NOMBRE_ARCHIVO', 'USUARIO', 'FEC_ARCHIVO', 'HORA_ARCHIVO', 'CANTIDAD', 'CLICS_TOTALES', 'CLICS_UNICOS', 'RESPUESTAS_TOTALES', 'RESPUESTAS_POSITIVAS']; } public function forArea(string $area) { $this->area = $area; return $this; } public function forUsuario(string $usuario) { $this->usuario = $usuario; return $this; } public function forFechaStart(string $fechaStart) { $this->fechaStart = $fechaStart; return $this; } public function forFechaEnd(string $fechaEnd) { $this->fechaEnd = $fechaEnd; return $this; } public function collection() { $mytime = Carbon::today()->subDays(7); $solicitudes = DB::connection('mysql_dconsulting') ->table('REPORTE_CAB') ->where([ ['cantidad', '<>', 0] ]); if ($this->fechaStart != '0') { $solicitudes = $solicitudes->whereDate('FEC_ARCHIVO', '>=', $this->fechaStart); $solicitudes = $solicitudes->whereDate('FEC_ARCHIVO', '<=', $this->fechaEnd); } else { $solicitudes = $solicitudes->whereDate('FEC_ARCHIVO', '>=', $mytime); } /*if ($this->area != '0') { $solicitudes = $solicitudes->where('AREA_EMPRESA', $this->area); }*/ if ($this->usuario != '0') { $solicitudes = $solicitudes->where('USUARIO', $this->usuario); } $solicitudes = $solicitudes->get(['IDENTIFICADOR', 'PRODUCTO', 'CAMPANIA', 'NOMBRE_ARCHIVO', 'USUARIO', 'FEC_ARCHIVO', 'HORA_ARCHIVO', 'CANTIDAD', 'CLICS_TOTALES', 'CLICS_UNICOS', 'RESPUESTAS_TOTALES', 'RESPUESTAS_POSITIVAS']); return $solicitudes; } }