Download the PHP package zegitz/laravel-csv-response without Composer

On this page you can find all versions of the php package zegitz/laravel-csv-response. 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-csv-response

Laravel CSV Response

This package adds a CSV response type to the Laravel ResponseFactory class. Because CSV is a data format, just like JSON, it should be possible to respond to a request with this format.

This small package offers a straightforward solution that deals with conversion, from array or collection of objects to comma separated values string, and character encoding.

Disclaimer

This package is just a pretty cool helper to create CSV responses without pain.

If you want to generate CSV (or Excel) files with a lot of options and more robustness you should take a look at Maatwebsite/Laravel-Excel.

Installation

Require this package with composer using the following command:

As of Laravel 5.5, this package will be automatically discovered and registered. For older version of Laravel, add the service provider in config/app.php.

Usage

Base data format

The csv() method is very flexible about data format. All this examples return exactly the same response.

Objects as rows

If the "rows" of the array of data passed to the method are objects, you have to implement the csvSerialize() method in this objects. This method is based in the same principle than the jsonSerialize() method that is already implemented into an Eloquent model. It should return data as an associative array.

For example:

CSV first row

When the "rows" of the data collection are associative arrays or objects, the package use the keys of the first row to define the first row of the CSV response. This first row is generaly used as column titles in this type of file.

In order to have a consistent response, you have to be sure that every row in the data collection has the same number of values and the keys in the same order.

Other parameters

The csv() function declaration, based on Laravel json() function, is the following.

Status

Typically, you should return your CSV with status 200 Ok but you are allowed to be imaginative. Maybe are you building a full REST-CSV API ;)

Headers

The default headers for this response are the following but you can overwrite it.

Note that the default charset and encoding are automatically overwrited if a custom encoding is specified in the options (see below).

Options

The last argument lets you define how the CSV is built and formated. We have defined a format that fits very well in most cases but the optimal configuration may depend on your environment (language, Microsoft Office version, etc.).

The default options are the following.


All versions of laravel-csv-response with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
illuminate/routing Version 5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0
illuminate/support Version 5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0
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 zegitz/laravel-csv-response contains the following files

Loading the files please wait ....