PHPackages                             8891/laravel-exportcsv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 8891/laravel-exportcsv

ActiveLaravel-extention[Utility &amp; Helpers](/categories/utility)

8891/laravel-exportcsv
======================

Export CSV via Middleware, no source modify, just composer require

01PHP

Since Feb 28Pushed 7y ago2 watchersCompare

[ Source](https://github.com/8891tech/laravel-exportcsv)[ Packagist](https://packagist.org/packages/8891/laravel-exportcsv)[ RSS](/packages/8891-laravel-exportcsv/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

8891/laravel-exportcsv Csv导出中间件
===============================

[](#8891laravel-exportcsv-csv导出中间件)

ExportCsv 解决 csv 统一下载导出的功能

- 客户端通过设定 Accept: text/csv 头部触发下载
- 支持大文件串流下载，解决内存超出问题
- 下载的 csv 可直接通过 excel 打开，无需导入
- 基于 league/csv 包实现 csv 导出
- 提供 `exporting` (正在导出) 和 `exported` (已导出) 事件，方便在导出前后做处理。譬如，审计
- 默认注入到 web 和 api 两组路由中，并删除 `page` 和 `pagesize` 两个请求参数

Requirement
-----------

[](#requirement)

- PHP 7 +
- Laravel 5.6 +

Usage
-----

[](#usage)

### Server

[](#server)

只需要 require 进来就可以，无需任何配置

```
composer require 8891/laravel-exportcsv

```

### Client

[](#client)

通过 fetch 异步下载

```
const downloadIfAttachment = response => {
  let contentDisposition = response.headers.get('Content-Disposition') || '';
  if (contentDisposition.toLowerCase().includes('attachment')) {
    let filename = contentDisposition.split('=').map(v => v.trim())[1];
    response.blob().then( blob => {
        let a = document.createElement("a"),
          url = URL.createObjectURL(blob);
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        setTimeout(function() {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);
        }, 0);
    });
    return false;
  }

  return response;
}

fetch(url, {
    headers: {
        'Accept': 'text/csv'
    }
})
// content-disposition: attachment; filename=data.csv
.then(downloadIfAttachment)
.then(response => {
    // do something
});
```

TODO
----

[](#todo)

- 增加通过参数指定 export=csv 触发下载
- 增加配置自定义排除的请求参数
- 增加判断 response 是 json 或 array 才能通过 csv 下载，否则报错

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/28166766?v=4)[8891](/maintainers/8891)[@8891](https://github.com/8891)

---

Top Contributors

[![8891tech](https://avatars.githubusercontent.com/u/13161304?v=4)](https://github.com/8891tech "8891tech (6 commits)")[![treerootboy](https://avatars.githubusercontent.com/u/1161481?v=4)](https://github.com/treerootboy "treerootboy (3 commits)")

### Embed Badge

![Health badge](/badges/8891-laravel-exportcsv/health.svg)

```
[![Health](https://phpackages.com/badges/8891-laravel-exportcsv/health.svg)](https://phpackages.com/packages/8891-laravel-exportcsv)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
