PHPackages                             ralphmorris/exporter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ralphmorris/exporter

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ralphmorris/exporter
====================

Export a collection of models to csv

1.0.2(6y ago)044MITPHPCI failing

Since Nov 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ralphmorris/exporter)[ Packagist](https://packagist.org/packages/ralphmorris/exporter)[ RSS](/packages/ralphmorris-exporter/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

Laravel CSV Export
==================

[](#laravel-csv-export)

Exporter is a package for Laravel that provides a simple csv export of any collection of models.

Installation
------------

[](#installation)

```
composer require ralphmorris/exporter

```

Usage
-----

[](#usage)

In your controller use:

```
use RalphMorris\Exporter\Exporter;
```

Then inside your method a simple call could look like:

```
public function export()
{
    $users = User::get();

    $exporter = new Exporter;

    return $exporter->exportToCsv($users);
}
```

You can also optionally specify the filename by providing a second parameter.

```
return $exporter->exportToCsv($users, 'my-file-name.csv');
```

### Speciying which columns to export

[](#speciying-which-columns-to-export)

If you only want to export certain columns from your model simply include the ExportableColumnsTrait trait in your model class and define a protected property of $exportableColumns with an array of the fields you would like to be exportable.

For example:

```
