PHPackages                             royalcms/data-export - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. royalcms/data-export

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

royalcms/data-export
====================

The Royalcms data-export package.

v5.0.0(6y ago)021MITPHPPHP &gt;=5.5.9

Since Sep 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/royalcms/royalcms-data-export)[ Packagist](https://packagist.org/packages/royalcms/data-export)[ Docs](http://royalcms.cn)[ RSS](/packages/royalcms-data-export/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Create zip files containing export data
=======================================

[](#create-zip-files-containing-export-data)

This package makes it easy to let a user download an export containing all the personal data. Such an export consists of a zip file containing all the user properties and related info.

You can create and mail such a zip by dispatching the `CreateCustomizeDataExportJob` job:

```
// somewhere in your app

use Royalcms\Component\DataExport\Jobs\CreateCustomizeDataExportJob;

// ...

dispatch(new CreateCustomizeDataExportJob(userModel());
```

The package will create a zip containing all the customize data. When the zip has been created, a link to it will be mailed to the user. By default, the zips are saved in a non-public location, and the user should be logged in to be able to download the zip.

You can configure which data will will be exported in the `selectCustomizeData ` method on the `model`.

```
// in your User model

public function selectCustomizeData(CustomizeDataSelection $customizeDataSelection) {
    $customizeDataSelection
        ->add('user.json', ['name' => $this->name, 'email' => $this->email])
        ->addFile(storage_path("avatars/{$this->id}.jpg");
        ->addFile('other-user-data.xml', 's3');
}
```

This package also offers an artisan command to remove old zip files.

You must add a disk named `data-exports` to `config/filesystems`. You can use any driver that you want. We recommend that your disk is not publicly accessible. If you're using the `local` driver, make sure you use a path that is not inside the public path of your app.

```
// in config/filesystems.php

// ...

'disks' => [

    'data-exports' => [
        'driver' => 'local',
        'root' => storage_path('app/data-exports'),
    ],

// ...
```

Usage
-----

[](#usage)

### Selecting customize data

[](#selecting-customize-data)

First, you'll have to prepare your user model. You should let your model implement the `Royalcms\Component\DataExport\ExportsCustomizeData` interface. This is what that interface looks like:

```
namespace Royalcms\Component\DataExport\Contracts;

interface ExportsCustomizeData
{
    public function selectCustomizeData(CustomizeDataSelection $customizeDataSelection);

    public function customizeDataExportName();

    public function getKey();
}
```

The `selectCustomizeData ` is used to determine the content of the customize download. Here's an example implementation:

```
// in your user model

public function selectCustomizeData(CustomizeDataSelection $customizeDataSelection) {
    $customizeDataSelection
        ->add('user.json', ['name' => $this->name, 'email' => $this->email])
        ->addFile(storage_path("avatars/{$this->id}.jpg");
        ->addFile('other-user-data.xml', 's3');
}
```

`$customizeDataSelection ` is used to determine the content of the zip file that the user will be able to download. You can call these methods on it:

- `add`: the first parameter is the name of the file in the inside the zip file. The second parameter is the content that should go in that file. If you pass an array here, we will encode it to JSON.
- `addFile`: the first parameter is a path to a file which will be copied to the zip. You can also add a disk name as the second parameter.

The name of the export itself can be set using the `customizeDataExportName` on the user. This will only affect the name of the download that will be sent as a response to the user, not the name of the zip stored on disk.

```
// on your user

public function customizeDataExportName(string $realFilename) {
    $userName = Str::slug($this->name);

    return "export-data-{$userName}.zip";
}
```

### Creating an export

[](#creating-an-export)

You can create a personal data export by executing this job somewhere in your application:

```
// somewhere in your app

use Royalcms\Component\DataExport\Jobs\CreateCustomizeDataExportJob;

// ...

dispatch(new CreateCustomizeDataExportJob(userModel());
```

By default, this job is queued. It will copy all files and content you selected in the `selectCustomizeData` on your user to a temporary directory. Next, that temporary directory will be zipped and copied over to the `data-exports` disk. A link to this zip will be mailed to the user.

### Securing the export

[](#securing-the-export)

We recommend that the `data-exports` disk is not publicly accessible. If you're using the `local` driver for this disk, make sure you use a path that is not inside the public path of your app.

### Customizing the queue

[](#customizing-the-queue)

You can customize the job that creates the zip file and mails it by extending the `Royalcms\Component\DataExport\Jobs\CreateCustomizeDataExportJob` and dispatching your own custom job class.

```
use Royalcms\Component\DataExport\Jobs\CreateCustomizeDataExportJob;

class MyCustomJobClass extends CreateCustomizeDataExportJob
{
    public $queue = 'my-custom-queue`
}
```

```
dispatch(new MyCustomJobClass(userModel()));
```

### Events

[](#events)

#### CustomizeDataSelected

[](#customizedataselected)

This event will be fired after the personal data has been selected. It has two public properties:

- `$customizeData`: an instance of `CustomizeData`. In your listeners you can call the `add`, `addFile` methods on this object to add extra content to the zip.
- `$data`: the data for which this personal data has been selected.

#### CustomizeDataExportCreated

[](#customizedataexportcreated)

This event will be fired after the personal data zip has been created. It has two public properties:

- `$zipFilename`: the name of the zip filename.
- `$data`: the data for which this zip has been created.

#### CustomizeDataExportDownloaded

[](#customizedataexportdownloaded)

This event will be fired after the export has been download. It has two public properties:

- `$zipFilename`: the name of the zip filename.
- `$data`: the data for which this zip has been created.

You could use this event to immediately clean up the downloaded zip.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2446d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1106638?v=4)[Hao.Dongfang](/maintainers/royalwang)[@royalwang](https://github.com/royalwang)

---

Top Contributors

[![royalwang](https://avatars.githubusercontent.com/u/1106638?v=4)](https://github.com/royalwang "royalwang (1 commits)")

### Embed Badge

![Health badge](/badges/royalcms-data-export/health.svg)

```
[![Health](https://phpackages.com/badges/royalcms-data-export/health.svg)](https://phpackages.com/packages/royalcms-data-export)
```

###  Alternatives

[orchidjs/tom-select

Tom Select is a dynamic, framework agnostic, and lightweight (~16kb gzipped) &lt;select&gt; UI control. With autocomplete and native-feeling keyboard navigation, it's useful for tagging, contact lists, country selectors, and so on.

2.1k1.6k](/packages/orchidjs-tom-select)

PHPackages © 2026

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