niiyz/laravel-csv

Laravel5 Simple CSV Downloader

1.0.1 2016-08-04 23:36 UTC

This package is auto-updated.

Last update: 2021-12-18 13:34:25 UTC


README

Laravel-CsvDownloader is Very Simple Csv Downloader

#Installation

Require this package in your composer.json and update composer.

"niiyz/laravel-csv": "~1.0.1"

After updating composer, add the ServiceProvider to the providers array in config/app.php

'Niiyz\Csv\CsvServiceProvider',

You can use the facade for shorter code. Add this to your aliases:

'Csv'       => 'Niiyz\Csv\Facades\Csv',

The class is bound to the ioC as csv

use Csv;

Sample.1

Csv::create([[1, 2, 3], [10, 20, 30]], []);
Csv::convertEncoding('UTF-8', 'SJIS-win');// ex. Japanese
return Csv::download('sample.csv');

Sample.2

$users = \User::where('type', '=', '1')->get(['name', 'birth_day'])->toArray();// from DB
$header = ['customer', 'birthday'];
Csv::create($users, $header);
Csv::convertEncoding('UTF-8', 'SJIS-win');// ex. Japanese
return Csv::download('customers.csv');