laravel-admin/docs/zh/model-grid-exporter.md
2022-09-21 11:59:53 +08:00

33 lines
671 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自定义导出
laravel-admin的数据表格默认支持导出csv文件
```php
<?php
namespace App\Admin\Extensions;
use Encore\Admin\Grid\Exporters\AbstractExporter;
class CustomExporter extends AbstractExporter
{
public function export()
{
$filename = $this->getTable().'.csv';
$data = $this->getData();
$output = '';
$headers = [
'Content-Encoding' => 'UTF-8',
'Content-Type' => 'text/csv;charset=UTF-8',
'Content-Disposition' => "attachment; filename=\"$filename\"",
];
response(rtrim($output, "\n"), 200, $headers)->send();
exit;
}
}
```