PHPackages                             netsells/exportable - 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. netsells/exportable

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

netsells/exportable
===================

Enables exporting of class data in PDF or CSV formats

1.0.1(7y ago)12081MITPHP

Since Jan 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/netsells/exportable-package)[ Packagist](https://packagist.org/packages/netsells/exportable)[ RSS](/packages/netsells-exportable/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Exportable
==========

[](#exportable)

[![Latest Version](https://camo.githubusercontent.com/a812a862ca5aa13ceac82e6b73e5e6adde7cc46680f848ce2c4ede4df6486e21/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6e657473656c6c732f6578706f727461626c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/netsells/exportable-package/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/e921bf3566279e9bdc066c0e95167ffcfb62a586a3074c175a50e55c4521bb50/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e657473656c6c732f6578706f727461626c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/netsells/exportable-package)

Allows easy exporting of data from Eloquent models

It is created and maintained by the [Netsells team](https://netsells.co.uk/)

Getting Started
---------------

[](#getting-started)

Install `Exportable` using Composer.

```
$ composer require netsells/exportable

```

### Implementation

[](#implementation)

This implementation of Exportable makes exporting data from Eloquent models to CSV or PDF formats simple. Simply extend the `Netsells\Exportable\ExportableModel` base class included in the package for any Eloquent model that needs to use the export functionality.

```
use Netsells\Exportable\ExportableModel;

class User extends ExportableModel

```

#### ExportableModel

[](#exportablemodel)

The base class for the exportable model implements and satisfies the `ExportableContract` interface that can be applied to other classes. The two traits that perform the exporting of data are imported here as well.

```
use Netsells\Exportable\Contracts\ExportableContract;
use Netsells\Exportable\Traits\ExportableCsv;
use Netsells\Exportable\Traits\ExportablePdf;

class ExportableModel extends Model implements ExportableContract
{
    use ExportablePdf;
    use ExportableCsv;

```

The two core methods for exporting data are as follows:

`public static function exportToPdf`

`public static function exportToCsv`

The remaining two methods in the class are used to build the layout closure used by Csvme to export the data to CSV format and retrieve constants safely should they be used to provide routes to config or views.

`public static function getLayoutClosure`

`public static function getConstant`

### Basic Usage

[](#basic-usage)

#### PDF

[](#pdf)

Exporting data to PDF format requires a view to format the output, the data to be exported and a list of headers. An example view is included with the package and custom views can easily be applied where desired.

```
  $users = User::all()->toArray();
  $headers = [
      "first_name"    => "First Name",
      "last_name"     => "Last Name",
      "email"         => "Email",
      "phone"         => "Phone",
  ];

  $view = "exportable\\pdf";
  User::exportToPdf($view, $users, $headers);
```

#### CSV

[](#csv)

Exporting data to CSV format simply needs the data and headers, if any, that are needed for the output. No special formatting is required since it is a CSV.

```
  $users = User::all()->toArray();
  $headers = [
      "first_name"    => "First Name",
      "last_name"     => "Last Name",
      "email"         => "Email",
      "phone"         => "Phone",
  ];

  User::exportToCsv($users, $headers);
```

### Advanced Usage

[](#advanced-usage)

Included in the package is a `exportable.php` file that contains the bare bones to set up data that can be used to set up the export to CSV or PDF formats. This can be modified to suit your requirements, with multiple sections for different exports.

```
  return [
    'pdf' => [
        'headers' => [
            // Map headers for PDF export here
        ],
        // View used to construct PDF export
        'view' => 'exportable\pdf',
    ],
    'csv' => [
        'headers' => [
            // Map headers for CSV export here
        ],
    ]
  ];
```

##### Example

[](#example)

```
  return [
    'user' => [
      'pdf' => [
          'headers' => [
            "first_name"    => "First Name",
            "last_name"     => "Last Name",
            "email"         => "Email",
            "phone"         => "Phone",
            "email"         => "Email",
          ],
          // View used to construct PDF export
          'view' => 'exportable\user_pdf',
      ],
    ],
    'admin' => [
      'pdf' => [
          'headers' => [
            "first_name"    => "First Name",
            "last_name"     => "Last Name",
            "email"         => "Email",
            "phone"         => "Phone",
            "email"         => "Email",
            "permission_level" => "Permissions",
          ],
          // View used to construct PDF export
          'view' => 'exportable\admin_pdf',
      ],
    ]
  ];
```

For simplicity you can add the paths to each config as constants on the model.

```
  class User extends ExportableModel
  {
      const ADMIN_PDF_CONFIG = 'exportable.admin.pdf';
      const USER_PDF_CONFIG = 'exportable.user.pdf';
```

Using the `getConstant` static method, the value of the constant can be retrieved. This method returns null if the constant is not found on the class. Using the value of the constant, the required config data can be used to export the data, as shown below.

```
  // Confirm class constant defined
  if ($configPath = User::getConstant('ADMIN_PDF_CONFIG')) {
      $config = Config::get($configPath);
      $headers = $config['headers'];
      $view = $config['view'];
      $users = User::all()->toArray();
      User::exportToPdf($view, $data, $headers);
  }
```

Built With
----------

[](#built-with)

- [Csvme](https://github.com/netsells/csvme) - An opinionated library that utilises the league/csv library
- [Dompdf](https://github.com/dompdf/dompdf) - Dompdf is an HTML to PDF converter

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 84.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fd3cc944adfb60bb9f271b2ebcf1dde1c26380682db0ba28e029cc42e09cebf?d=identicon)[spamoom](/maintainers/spamoom)

![](https://www.gravatar.com/avatar/fed186a8d3a5446e6921c3eaa158af650ee2ced5858fc618f798d4b37a42ebab?d=identicon)[shaundoudican-ns](/maintainers/shaundoudican-ns)

---

Top Contributors

[![shaundoudican-ns](https://avatars.githubusercontent.com/u/45259212?v=4)](https://github.com/shaundoudican-ns "shaundoudican-ns (11 commits)")[![bethandvincent](https://avatars.githubusercontent.com/u/29337454?v=4)](https://github.com/bethandvincent "bethandvincent (1 commits)")[![samturrell](https://avatars.githubusercontent.com/u/5918348?v=4)](https://github.com/samturrell "samturrell (1 commits)")

### Embed Badge

![Health badge](/badges/netsells-exportable/health.svg)

```
[![Health](https://phpackages.com/badges/netsells-exportable/health.svg)](https://phpackages.com/packages/netsells-exportable)
```

###  Alternatives

[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[consoletvs/invoices

Generate PDF invoices for your customers in laravel

455275.5k](/packages/consoletvs-invoices)[nucleos/dompdf-bundle

This bundle provides a wrapper for using dompdf inside symfony.

54882.8k1](/packages/nucleos-dompdf-bundle)[dino/dompdf-module

A Zend Framework 2 module for incorporating DOMPDF support.

61465.1k8](/packages/dino-dompdf-module)[omaralalwi/gpdf

Custom PDF wrapper supporting Arabic language

15411.6k](/packages/omaralalwi-gpdf)[phpnt/yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

158.9k](/packages/phpnt-yii2-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
