Download the PHP package sinemacula/laravel-resource-exporter without Composer

On this page you can find all versions of the php package sinemacula/laravel-resource-exporter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-resource-exporter

Laravel Resource Exporter

[![Latest Stable Version](https://img.shields.io/packagist/v/sinemacula/laravel-resource-exporter.svg)](https://packagist.org/packages/sinemacula/laravel-resource-exporter) [![PHP Version](https://img.shields.io/packagist/dependency-v/sinemacula/laravel-resource-exporter/php.svg)](https://packagist.org/packages/sinemacula/laravel-resource-exporter) [![Laravel Version](https://img.shields.io/packagist/dependency-v/sinemacula/laravel-resource-exporter/laravel/framework.svg?label=laravel)](https://packagist.org/packages/sinemacula/laravel-resource-exporter) [![Build Status](https://github.com/sinemacula/laravel-resource-exporter/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-resource-exporter/actions/workflows/tests.yml) [![Quality Gates](https://github.com/sinemacula/laravel-resource-exporter/actions/workflows/quality-gates.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-resource-exporter/actions/workflows/quality-gates.yml) [![Maintainability](https://qlty.sh/gh/sinemacula/projects/laravel-resource-exporter/maintainability.svg)](https://qlty.sh/gh/sinemacula/projects/laravel-resource-exporter) [![Code Coverage](https://qlty.sh/gh/sinemacula/projects/laravel-resource-exporter/coverage.svg)](https://qlty.sh/gh/sinemacula/projects/laravel-resource-exporter) [![Total Downloads](https://img.shields.io/packagist/dt/sinemacula/laravel-resource-exporter.svg)](https://packagist.org/packages/sinemacula/laravel-resource-exporter) [![License](https://img.shields.io/github/license/sinemacula/laravel-resource-exporter.svg)](LICENSE)

Return any API resource in the format the client asks for. Add one trait to a JsonResource, declare the columns that make sense as a table, and the same endpoint that serves JSON will stream CSV, TSV, XLSX, XML, JSON, or NDJSON when the request asks for it - over the Accept header or a ?format= query parameter - with no second controller and no bespoke serialization code.

Rows are pulled lazily from the source, so CSV, TSV, JSON, XML, and NDJSON exports stay flat in memory even for large queries. XLSX is built as a temporary workbook before the response can flush, so large spreadsheets are best queued to disk behind a signed URL. The same engine drives inline downloads, queued exports, and one-off fluent exports.

The package is registered automatically through Laravel's package auto-discovery; publish the config (see below) to register custom formats or tune the negotiation limits.

How It Works

There are two doors onto one streaming engine:

Formats split by dimensionality:

A few rules hold across the surface:

Installation

The service provider is auto-discovered. XLSX support is optional - pull it in when you need it:

Configuration

Publish the package configuration:

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

Key Description Default
default Default format for explicit export builders (env EXPORTER_DEFAULT). csv
alias The container / facade accessor alias for the manager (env EXPORTER_ALIAS). exporter
formats Custom negotiable formats registered with the shared media-type registry. []
negotiation Query-endpoint settings: default_format, max_rows, per_page, chunk_size. see file
audit Optional log channel for the ExportCompleted audit payload. null

Usage

Content negotiation

Add the RespondsWithExports trait and implement ProvidesTabularExport on your resource. The resource keeps returning JSON; a TabularSchema describes the table the tabular formats produce:

The route is unchanged - return the resource or collection exactly as you already do:

The response format then follows the request:

Supported formats

Format Media type(s) Shape
json application/json Hierarchical (default)
csv text/csv Tabular
tsv text/tab-separated-values Tabular
xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Tabular
xml application/xml, text/xml Hierarchical
ndjson application/x-ndjson, application/jsonl Hierarchical

Columns

Column::make($key, $heading) reads $key off each row; chainable modifiers cast, format, aggregate, and gate it:

Count and sum aggregates are folded into the query (withCount / withSum); join aggregates eager-load the relation, so none add per-row queries.

Column visibility

Tabular exports (CSV / TSV / XLSX) resolve each column straight off the raw model attribute via data_get. That read is deliberately fast and constant-memory, but it does not route through the resource's toArray() / $hidden / when() gating - so a $hidden attribute is still emitted, and field visibility is not inherited from the resource. Gating a field out of an export is the schema author's job, expressed with ->visible() on the column:

A column whose ->visible() gate returns false is dropped entirely - from the heading row and from every data row - so its value can never leak through any cell or aggregate path. The gate sees only the request (no row) and is evaluated once when the schema is built.

Explicit exports

When you want bytes on demand rather than over HTTP, build an export through the facade:

Query endpoint (paginated JSON or full export)

ResourceExport::forQuery() serves a paginated JSON collection for a normal request and streams the full dataset for an export request, from one route - with the safety rails a full-table stream needs:

The full set is capped at negotiation.max_rows (default 10000); raise it per call with ->unlimited() or ->maxRows(), or queue the export. Authorization is explicit: call authorizeUsing() (or withoutAuthorization() to opt out deliberately), or the streamed export refuses to run.

Queued exports

For large tabular datasets, queue the export to a disk and hand the user a signed URL when it lands:

The queued pipeline writes tabular formats (CSV, TSV, XLSX). It streams chunk by chunk into a local staging file and fires ExportStarting, RowsExported, ExportCompleted (carrying a signed temporary URL), and ExportFailed. The query is described by a serializable specification - constrain it with the query verbs on the builder rather than passing a live builder. HTTP streaming failures after bytes have started are reported separately through StreamExportFailed, with the format, actor and number of rows written.

Testing

Exporter::fake() swaps the engine for a recorder, so tests assert what would have been exported without producing bytes or dispatching jobs - mirroring Storage::fake() and Bus::fake():

Custom formats

Register an additional negotiable format through the formats block in config/exporter.php; the negotiated and explicit paths share one registry, so a custom format is reachable from both.

For a config-cache friendly tabular format, bind an ExportFormat in a service provider and list the binding key in config:

Closures and ExportFormat instances also work when the config file is not cached.

Requirements

Testing

Changelog

See CHANGELOG.md for a list of notable changes.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for guidelines on branching, commits, code quality, and pull requests.

Security

If you discover a security vulnerability, please report it responsibly. See SECURITY.md for the disclosure policy and contact details.

License

Licensed under the Apache License, Version 2.0.


All versions of laravel-resource-exporter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-filter Version *
ext-xmlwriter Version *
laravel/framework Version ^12.0 || ^13.0
league/csv Version ^9.27
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sinemacula/laravel-resource-exporter contains the following files

Loading the files please wait ...