自定义导出

laravel-admin的数据表格默认支持导出csv文件,

  1. <?php
  2. namespace App\Admin\Extensions;
  3. use Encore\Admin\Grid\Exporters\AbstractExporter;
  4. class CustomExporter extends AbstractExporter
  5. {
  6. public function export()
  7. {
  8. $filename = $this->getTable().'.csv';
  9. $data = $this->getData();
  10. $output = '';
  11. $headers = [
  12. 'Content-Encoding' => 'UTF-8',
  13. 'Content-Type' => 'text/csv;charset=UTF-8',
  14. 'Content-Disposition' => "attachment; filename=\"$filename\"",
  15. ];
  16. response(rtrim($output, "\n"), 200, $headers)->send();
  17. exit;
  18. }
  19. }