- PHP version 5.6
- Laravel 5.2
- maatwebsite/excel: 2.1.0
The code below works fine in localhost, but when i check with Live Server (AWS Light Sail), returns Corrupted Excel/PDF File. I have given all required permissions recommended by maatwebiste. And when i try to dd() the result inside the function the server returns 500 Internal server error response. When i check with some forums someone saying the problem occures with while spaces inside the function and before the < ? php Tag, I tried with the solution but returns the same. Any Help Would be well appreciated.
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());
}
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2DR2GM5
via IFTTT
Aucun commentaire:
Enregistrer un commentaire