public static function generate_query_excel($array) { $dir = public_path('excel'); array_map('unlink', glob($dir . '/*')); $file = \Excel::create($array['node']->plural . '_' . date('Y-m-d'), function ($excel) use($array) { $excel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $excel->sheet($array['node']->plural, function ($sheet) use($array) { $col_array = []; foreach ($array['fields'] as $field) { array_push($col_array, $field->label); } $sheet->row(1, $col_array); $sheet->row(1, function ($row) { $row->setFontWeight('bold'); }); $fila = 2; foreach ($array['items'] as $item) { $sheet->row($fila, AdminList::make_fields_values($item, $array['fields'], '', 'excel')); $fila++; } }); })->store('xlsx', $dir, true); return response()->download($file['full']); }