Laravel Resource Exporter is a versatile package that enables seamless conversion of Laravel JsonResource and JsonResourceCollection objects into various exportable formats. The package is designed with extensibility in mind, allowing you to easily add custom export formats via a driver-based architecture.
- Format Flexibility: Export your resources to various formats using customizable drivers, making it easy to extend or adapt to new formats.
- Driver-Based Architecture: Each export format is handled by a dedicated driver class, ensuring clean, maintainable, and extendable code.
- Facade Support: Utilize an intuitive facade for easy access to export functionality, streamlining the process of converting resources.
- CSV
- XML
To install the Laravel Resource Exporter, run the following command in your project directory:
composer require sinemacula/laravel-resource-exporter
After installation, publish the package configuration to customize it according to your needs:
php artisan vendor:publish --provider="SineMacula\Exporter\ExporterServiceProvider"
This command publishes the package configuration file to your application's config directory, allowing you to modify aspects such as the available export formats, driver configurations, and more.
The Laravel Resource Exporter provides an easy-to-use facade for exporting resources. Below is an example of how to export a resource or a collection:
use SineMacula\Exporter\Facades\Exporter;
use App\Http\Resources\YourResource;
// Export an item as CSV
$csv = Exporter::format('csv')->exportItem(new YourResource($item));
// Export a collection as XML
$xml = Exporter::format('xml')->exportCollection(YourResource::collection($collection));
Contributions are welcome and will be fully credited. We accept contributions via pull requests on GitHub.
If you discover any security related issues, please email instead of using the issue tracker.
The Laravel Resource Exporter repository is open-sourced software licensed under the Apache License, Version 2.0.