sinemacula / laravel-resource-exporter
A versatile Laravel package for exporting JsonResource and JsonResourceCollection objects into various formats with customizable drivers.
Installs: 14 110
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/sinemacula/laravel-resource-exporter
Requires
- php: ^8.3
- ext-dom: *
- ext-simplexml: *
- illuminate/http: *
- illuminate/support: *
Requires (Dev)
- brianium/paratest: ^7.8
- friendsofphp/php-cs-fixer: ^3.85
- orchestra/testbench: ^9.0 || ^10.0
- phpstan/extension-installer: ^1.4
- phpstan/phpdoc-parser: ^2.2
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5.3
- slevomat/coding-standard: ^8.20
- squizlabs/php_codesniffer: ^3.13
- dev-master
- v2.0.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- dev-feature/agents-integration
- dev-develop
- dev-dependabot/composer/nesbot/carbon-3.8.4
- dev-dependabot/composer/league/commonmark-2.6.0
- dev-dependabot/composer/laravel/framework-11.31.0
- dev-dependabot/composer/symfony/process-7.1.7
- dev-dependabot/composer/symfony/http-foundation-7.1.7
This package is auto-updated.
Last update: 2026-02-20 14:29:22 UTC
README
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
csvxml
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 nameexporters: named exporters and theirdriver+ optionsalias: container/facade accessor alias (defaults toexporter)
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.