sinemacula/laravel-resource-exporter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sinemacula/laravel-resource-exporter

Composer 安装命令:

composer require sinemacula/laravel-resource-exporter

包简介

A versatile Laravel package for exporting JsonResource and JsonResourceCollection objects into various formats with customizable drivers.

README 文档

README

Latest Stable Version Build Status Maintainability Code Coverage Total Downloads

Laravel Resource Exporter is a Laravel integration package for converting JsonResource and ResourceCollection payloads into export-friendly formats.

The package includes:

  • a manager (ExportManager) for resolving configured drivers
  • built-in CSV and XML drivers
  • a facade (SineMacula\Exporter\Facades\Exporter) for convenient usage
  • extension hooks for custom export drivers without changing core package code

Features

  • Export arrays, single resources, and resource collections
  • Select a driver explicitly (csv, xml) or use the configured default
  • Exclude fields consistently across drivers using withoutFields()
  • Customize per-driver options through config/exporter.php
  • Register custom drivers via ExportManager::extend()

Supported Drivers

  • csv
  • xml

Installation

To install the Laravel Resource Exporter, run the following command in your project directory:

composer require sinemacula/laravel-resource-exporter

Configuration

After installation, publish the package configuration:

php artisan vendor:publish --provider="SineMacula\Exporter\ExporterServiceProvider"

This creates config/exporter.php, where you can control:

  • default: the default exporter name
  • exporters: named exporters and their driver + options
  • alias: container/facade accessor alias (defaults to exporter)

Usage

Basic usage

use SineMacula\Exporter\Facades\Exporter;
use App\Http\Resources\YourResource;

// Export a single resource as CSV
$csv = Exporter::format('csv')->exportItem(new YourResource($item));

// Export a collection as XML
$xml = Exporter::format('xml')->exportCollection(YourResource::collection($collection));

Field exclusion

$csv = Exporter::format('csv')
    ->withoutFields(['internal_id', 'debug'])
    ->exportCollection(YourResource::collection($collection));

On-demand exporters

use SineMacula\Exporter\Facades\Exporter;

// Build an exporter from ad-hoc config
$exporter = Exporter::build([
    'driver' => 'csv',
    'delimiter' => ';',
]);

Custom drivers

use SineMacula\Exporter\ExportManager;

app(ExportManager::class)->extend('json', function ($app, array $config) {
    return new App\Exporters\JsonExporter($config);
});

Testing

composer test
composer test-coverage
composer check

Contributing

Contributions are welcome via GitHub pull requests.

Security

If you discover a security issue, please contact Sine Macula directly rather than opening a public issue.

License

Licensed under the Apache License, Version 2.0.

统计信息

  • 总下载量: 17.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-08-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固