承接 kfoobar/laravel-csv-response 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kfoobar/laravel-csv-response

最新稳定版本:v1.0.2

Composer 安装命令:

composer require kfoobar/laravel-csv-response

包简介

CSV Response for Laravel

README 文档

README

A lightweight Laravel package that adds a response macro for streaming CSV data directly to the browser, optimized for memory efficiency and designed to handle large datasets with ease.

Installation

You can install the package via Composer. Run the following command in your terminal:

composer require kfoobar/laravel-csv-response

After installing the package, publish the configuration file using the Artisan command:

php artisan vendor:publish --tag=csv-response-config

This will create a csv-response.php file in your config directory, where you can customize the package settings.

How to Use

return response()->csv(
    rows: [], 
    options: [],
    inline: true // false = force download
);

Display CSV Inline

To render the CSV directly in the browser:

$rows = Product::all()
    ->map(function (Product $product) {
        return [
            $product->sku,
            $product->name,
            $product->price,
        ];
    })
    ->toArray();

return response()->csv($rows, inline: true);

Download the CSV

To force the CSV file to download:

$rows = Product::all()
    ->map(function (Product $product) {
        return [
            $product->sku,
            $product->name,
            $product->price,
        ];
    })
    ->toArray();

return response()->csv($rows, inline: false);

Using Options

You may customize the CSV output using the options parameter:

$rows = Product::all()
    ->map(function (Product $product) {
        return [
            $product->sku,
            $product->name,
            $product->price,
        ];
    })
    ->toArray();

$options = [
    'delimiter' => ',',
    'filename'  => 'catalog.csv',
    'headers'   => ['sku', 'name', 'price'],
];

return response()->csv($rows, $options, inline: false);

You can also include the headers directly as the first row in the $rows array if you prefer not to define them in the headers option.

Contribution

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes and ensure tests pass.
  4. Submit a pull request with a detailed description of your changes.

License

This package is open-source and released under the MIT License. See LICENSE for more information.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-05