下面的代码在本地主机上工作正常,但是当我使用Live检查时 服务器(AWS Light Sail),返回损坏的Excel / PDF文件。我已授予maatwebiste建议的所有必需权限。当我尝试dd()函数内部的结果时,服务器返回500 Internal server error response。当我在一些论坛中查询时,有人说问题出在功能内部以及<?之前。 php Tag,我尝试使用该解决方案,但返回的结果相同。任何帮助 将不胜感激。
public function export(Request $request, $type = 'pdf')
{
try {
$data = $this->getReport($request->All(),new ServiceReport());
return Excel::create('service_report', function ($excel) use ($data) {
$excel->setTitle('ServiceReport');
$excel->setDescription('Service Repor');
$excel->sheet('AxisPro-ServiceReport', function ($sheet) use ($data) {
$sheet->setOrientation('portrait');
$this->setColumnHeader($sheet,['Invoice No','Date','Customer']);
if (!empty($data)) {
foreach ($data as $key => $row) {
$i = $key + 2;
$sheet->cell('A' . $i, $row->invoice_no);
$sheet->cell('B' . $i, sql2date($row->transaction_date));
$sheet->cell('C' . $i, $row->customer_name)->setAutoSize(false);
}
}
$sheet->setPageMargin(0);
$sheet->setBorder('A1:' . $sheet->getHighestColumn() . $sheet->getHighestRow());
$sheet->row(1, function ($row) {
$row->setBackground('#d9d9d9');
});
});
})->download($type);
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
}