okamok/csv-download-library

For Laravel CSV file download

1.0.1 2018-11-29 06:09 UTC

This package is auto-updated.

Last update: 2024-10-13 20:08:52 UTC


README

Total downloads Software License

CSV file download library.

Installation

Via Composer

$ composer require okamok/csv-download-library

Usage

This is sample controller for Laravel

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Okamok\CsvDownloadLibrary\CsvCreate;    //csv-download-library
use Illuminate\Support\Facades\Response;

class TopController extends Controller
{
    public function index(Request $request)
    {
        //sample header
        $csvHeader = ['title1','title2','title3'];

        //sample data(All users data)
        $data = User::get()->toArray();
        //you also can use Array for data
        //$data = [['aaa','bbb','ccc'], ['ddd','eeee','ffff']];

        //sample file name
        $fileName = 'test.csv';

        //use this library
        $ret = CsvCreate::getCsvData($data, $csvHeader, $fileName, 'UTF-8');

        //CSV output
        return Response::make($ret['csv'], 200, $ret['headers']);
    }
}

License

The MIT License (MIT).