nethercore / csv-exporter

laravel 的 CSV 导出工具

1.0.1 2024-09-10 01:23 UTC

This package is auto-updated.

Last update: 2024-09-10 20:35:18 UTC


README

通过 composer 安装

composer require nethercore/csv-exporter

使用方法

生成的文件将出现在 App/Exports/{name}Export.php 中

对于嵌套的名称或模型文件,请使用双反斜杠。

php artisan make:export {name} {model}

例如,运行 php artisan make:export Wharehouse\\Product Stock\\Item 将使用 Models/Stock/Item.php 在导出文件内部创建 app/Exports/Wharehouse/ProductExport.php

示例代码

namespace App\Exports;

use App\Models\Product;
use Nethercore\CsvExporter\Interfaces\BaseExporterInterface;
use Nethercore\CsvExporter\Traits\StreamResponseTrait;
use Symfony\Component\HttpFoundation\StreamedResponse;

final class ProductExport implements BaseExporterInterface
{
    use StreamResponseTrait;
    ...
}
use App\Exports\ProductExport;

class ProductController extends Controller
{
    public function export()
    {
        return (new ProductExport('some product title'))->export());
    }
}