innovator-japan/laravel-csv

A library that manipulates CSV with Laravel

0.4.2 2019-06-25 04:30 UTC

This package is auto-updated.

Last update: 2024-11-18 05:24:24 UTC


README

CircleCI License

Features

  • Easily export to csv from collection
  • Highly memory efficient
  • Wrapper around League\Csv

Requirements

  • PHP 7.1.3 or later
  • Laravel 5.6 or later
  • mbstring extension

Installation

This project using composer.

$ composer require innovator-japan/laravel-csv

Usage

Exporting a database table as a CSV

1️⃣ First of all, Create this class.

<?php

namespace App\Export;

use App\User;
use Illuminate\Database\Query\Builder;
use InnovatorJapan\LaravelCsv\AbstractCsv;
use InnovatorJapan\LaravelCsv\Exportable;

class UserCsv extends AbstractCsv
{
    use Exportable;

    public function query(): Builder
    {
        return User::latest()->getQuery();
    }
}

2️⃣ Then you will be able to download it.

use App\Export\UserCsv;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function export()
    {
        return (new UserCsv())->download('user.csv');
    }
}

Importing CSV records into a database table

Comming soon...

Maintainers

Innovator Japan Inc.

Contributing

Please see CONTRIBUTING for details.

License

MIT © Innovator Japan Inc.