This is what I have currently Export class
class ReportExcel implements FromArray, withHeadings
{
use Exportable;
protected $items;
public function __construct(array $items)
{
$this->items= $items;
}
public function headings(): array
{
return ["Opcion 1", "Opcion 2", "Opcion 3", "Nombres", "Apellidos", "Telefono", "Correo",
"Pais", "Pais Otro", "Edad", "Adventista", "Estudia la Biblia", "Peticion", "Fecha"];
}
public function array(): array
{
return $this->items;
}
}
method in my controller
public function downloadExcel(Request $request)
{
if ($request->country == null) {
$item = Form::get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone',
'email', 'country_id', 'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
} else {
$item = Form::where('country_id', $request->country)->orderByDesc('created_at')
->get(['option_1', 'option_2', 'option_3', 'name', 'lastname', 'phone', 'email', 'country_id',
'country_other', 'age', 'adventist', 'study', 'petition', 'date_answered']);
}
$items[] = $item;
// return (new ReportExcel($items))->download('invoices.csv', Excel::CSV,
// ['Content-Type' => 'text/csv']);
return Excel::download(new ReportExcel($items), 'reporte.csv');
}
I have tried both ways seen in my controller neither downloads anything I do see something like this, if I change the extension to xls
or xlsx
the data is unreadable as there are a ton on symbols that show up as well
What am I doing wrong? How can I get this to download an actual excel file?