sinemacula/laravel-resource-exporter

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

v1.0.1 2024-08-22 01:04 UTC

This package is auto-updated.

Last update: 2024-08-22 01:04:34 UTC


README

Latest Stable Version Build Status StyleCI Maintainability Test Coverage Total Downloads

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.

Features

  • 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.

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 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.

Usage

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));

Contributing

Contributions are welcome and will be fully credited. We accept contributions via pull requests on GitHub.

Security

If you discover any security related issues, please email instead of using the issue tracker.

License

The Laravel Resource Exporter repository is open-sourced software licensed under the Apache License, Version 2.0.