{"id":13828330,"url":"https://github.com/spatie/laravel-personal-data-export","last_synced_at":"2025-05-14T07:08:13.983Z","repository":{"id":34290053,"uuid":"174338628","full_name":"spatie/laravel-personal-data-export","owner":"spatie","description":"Create zip files containing personal data","archived":false,"fork":false,"pushed_at":"2025-02-19T07:05:59.000Z","size":248,"stargazers_count":540,"open_issues_count":0,"forks_count":29,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-14T03:57:39.089Z","etag":null,"topics":["download","gdpr","personal","zip"],"latest_commit_sha":null,"homepage":"https://freek.dev/1290-a-package-to-create-personal-data-exports","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2019-03-07T12:18:40.000Z","updated_at":"2025-04-04T04:40:58.000Z","dependencies_parsed_at":"2024-08-04T09:08:23.883Z","dependency_job_id":"1d9014f6-aaa1-4d82-bcd2-c888dba92a17","html_url":"https://github.com/spatie/laravel-personal-data-export","commit_stats":{"total_commits":215,"total_committers":30,"mean_commits":7.166666666666667,"dds":"0.45581395348837206","last_synced_commit":"eff3a5c81f209ffc6dc354e3918ae8ab4783e1bf"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-personal-data-export","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-personal-data-export/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-personal-data-export/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-personal-data-export/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-personal-data-export/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092656,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["download","gdpr","personal","zip"],"created_at":"2024-08-04T09:02:41.723Z","updated_at":"2025-05-14T07:08:13.930Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://spatie.be/open-source/support-us"],"categories":["PHP"],"sub_categories":[],"readme":"# Create zip files containing personal data\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-personal-data-export.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-personal-data-export)\n[![run-tests](https://github.com/spatie/laravel-personal-data-export/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-personal-data-export/actions/workflows/run-tests.yml)\n![Check \u0026 fix styling](https://github.com/spatie/laravel-personal-data-export/workflows/Check%20\u0026%20fix%20styling/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-personal-data-export.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-personal-data-export)\n\nThis 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.\n\nYou can create and mail such a zip by dispatching the `CreatePersonalDataExportJob` job:\n\n```php\n// somewhere in your app\n\nuse Spatie\\PersonalDataExport\\Jobs\\CreatePersonalDataExportJob;\n\n// ...\n\ndispatch(new CreatePersonalDataExportJob(auth()-\u003euser()));\n```\n\nThe package will create a zip containing all the personal 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.\n\nYou can configure which data will be exported in the `selectPersonalData` method on the `user`.\n\n```php\n// in your User model\n\npublic function selectPersonalData(PersonalDataSelection $personalDataSelection): void {\n    $personalDataSelection\n        -\u003eadd('user.json', ['name' =\u003e $this-\u003ename, 'email' =\u003e $this-\u003eemail])\n        -\u003eaddFile(storage_path(\"avatars/{$this-\u003eid}.jpg\"))\n        -\u003eaddFile('other-user-data.xml', 's3');\n}\n```\n\nYou can store files in a directory of the archive. For this, add the directory path as the third parameter.\n\n```php\npublic function selectPersonalData(PersonalDataSelection $personalDataSelection): void {\n    $personalDataSelection\n        -\u003eaddFile(storage_path(\"avatars/{$this-\u003eid}.jpg\"), directory: 'avatars');\n}\n```\n\nThis package also offers an artisan command to remove old zip files.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-personal-data-export.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-personal-data-export)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-personal-data-export\n```\n\nYou need to use this macro in your routes file. It'll register a route where users can download their personal data exports.\n\n```php\n// in your routes file\n\nRoute::personalDataExports('personal-data-exports');\n```\n\nYou must add a disk named `personal-data-exports` to `config/filesystems` (the name of the disk can be configured in `config/personal-data-export`). 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.\n\n```php\n// in config/filesystems.php\n\n// ...\n\n'disks' =\u003e [\n\n    'personal-data-exports' =\u003e [\n        'driver' =\u003e 'local',\n        'root' =\u003e storage_path('app/personal-data-exports'),\n    ],\n\n// ...\n```\n\nTo automatically clean up older personal data exports, you can schedule this command in your console kernel:\n\n```php\n// app/Console/Kernel.php\n\nprotected function schedule(Schedule $schedule)\n{\n   $schedule-\u003ecommand('personal-data-export:clean')-\u003edaily();\n}\n```\n\nOptionally, you can publish the config file with:\n\n```php\nphp artisan vendor:publish --provider=\"Spatie\\PersonalDataExport\\PersonalDataExportServiceProvider\" --tag=\"personal-data-export-config\"\n```\n\nThis is the content of the config file, which will be published at `config/personal-data-export.php`:\n\n```php\nreturn [\n    /*\n     * The disk where the exports will be stored by default.\n     */\n    'disk' =\u003e 'personal-data-exports',\n\n    /*\n     * The amount of days the exports will be available.\n     */\n    'delete_after_days' =\u003e 5,\n\n    /*\n     * Determines whether the user should be logged in to be able\n     * to access the export.\n     */\n    'authentication_required' =\u003e true,\n\n    /*\n     * The notification which will be sent to the user when the export\n     * has been created.\n     */\n    'notification' =\u003e \\Spatie\\PersonalDataExport\\Notifications\\PersonalDataExportedNotification::class,\n\n    /*\n     * Configure the queue and connection used by `CreatePersonalDataExportJob`\n     * which will create the export.\n     */\n    'job' =\u003e [\n        'queue' =\u003e null,\n        'connection' =\u003e null,\n    ],\n];\n\n```\n\n## Usage\n\n### Selecting personal data\n\nFirst, you'll have to prepare your user model. You should let your model implement the `Spatie\\PersonalDataExport\\ExportsPersonalData` interface. This is what that interface looks like:\n\n```php\nnamespace Spatie\\PersonalDataExport;\n\ninterface ExportsPersonalData\n{\n    public function selectPersonalData(PersonalDataSelection $personalDataSelection): void;\n\n    public function personalDataExportName(): string;\n}\n```\n\nThe `selectPersonalData` is used to determine the content of the personal download. Here's an example implementation:\n\n```php\n// in your user model\n\npublic function selectPersonalData(PersonalDataSelection $personalDataSelection): void {\n    $personalDataSelection\n        -\u003eadd('user.json', ['name' =\u003e $this-\u003ename, 'email' =\u003e $this-\u003eemail])\n        -\u003eaddFile(storage_path(\"avatars/{$this-\u003eid}.jpg\"))\n        -\u003eaddFile('other-user-data.xml', 's3');\n}\n```\n\n`$personalData` 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:\n\n- `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.\n- `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.\n\nThe name of the export itself can be set using the `personalDataExportName` 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.\n\n```php\n// on your user\n\npublic function personalDataExportName(): string {\n    $userName = Str::slug($this-\u003ename);\n\n    return \"personal-data-{$userName}.zip\";\n}\n```\n\n### Creating an export\n\nYou can create a personal data export by executing this job somewhere in your application:\n\n```php\n// somewhere in your app\n\nuse Spatie\\PersonalDataExport\\Jobs\\CreatePersonalDataExportJob;\n\n// ...\n\ndispatch(new CreatePersonalDataExportJob(auth()-\u003euser()));\n```\n\nBy default, this job is queued. It will copy all files and content you selected in the `selectPersonalData` on your user to a temporary directory. Next, that temporary directory will be zipped and copied over to the `personal-data-exports` disk. A link to this zip will be mailed to the user. \n\n### Securing the export\n\nWe recommend that the `personal-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.\n\nWhen the user clicks the download link in the mail that gets sent after creating the export, a request will be sent to underlying `PersonalDataExportController`. This controller will check if there is a user logged in and if the request personal data zip belongs to the user. If this is the case, that controller will stream the zip to the user.\n\nIf you don't want to enforce that a user should be logged in to able to download a personal data export, you can set the `authentication_required` config value to `false`. Setting the value to `false` is less secure because anybody with a link to a zip file will be able to download it, but because the name of the zip file contains many random characters, it will be hard to guess it.\n\n### Translating the notification\n\nYou need to publish the translations:\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\PersonalDataExport\\PersonalDataExportServiceProvider\" --tag=\"personal-data-export-translations\"\n```\n\n### Customizing the mail\n\nYou can customize the mailable itself by creating your own mailable that extends `Spatie\\PersonalDataExport\\Notifications\\PersonalDataExportedNotification` and register the class name of your mailable in the `mailable` config key of `config/personal-data-export.php`.\n\nHere is an example:\n\n```php\nuse Spatie\\PersonalDataExport\\Notifications\\PersonalDataExportedNotification as SpatiePersonalDataExportedNotification;\nclass PersonalDataExportedNotification extends SpatiePersonalDataExportedNotification\n{\n    public function via($notifiable)\n    {\n        return ['mail'];\n    }\n    public function toMail($notifiable)\n    {\n        $downloadUrl = route('personal-data-exports', $this-\u003ezipFilename);\n        if (static::$toMailCallback) {\n            return call_user_func(static::$toMailCallback, $notifiable, $downloadUrl);\n        }\n        return (new MailMessage)\n            -\u003esubject(trans('personal-data-exports.notifications.subject'))\n            -\u003eline(trans('personal-data-exports.notifications.instructions'))\n            -\u003eaction(trans('personal-data-exports.notifications.action'), $downloadUrl)\n            -\u003eline(trans('personal-data-exports.notifications.deletion_message', ['date' =\u003e $this-\u003edeletionDatetime-\u003eformat('Y-m-d H:i:s')]));\n    }\n}\n```\n\nThen register the class name of your mailable in the `mailable` config key of `config/personal-data-export.php`\n\n```php\n    /*\n     * Something like that\n     */\n    'notification' =\u003e \\App\\Notifications\\PersonalDataExportedNotification::class,\n```\n\n### Customizing the queue\n\nYou can customize the job that creates the zip file and mails it by extending the `Spatie\\PersonalDataExport\\Jobs\\CreatePersonalDataExportJob` and dispatching your own custom job class.\n\n```php\nuse Spatie\\PersonalDataExport\\Jobs\\CreatePersonalDataExportJob;\n\nclass MyCustomJobClass extends CreatePersonalDataExportJob\n{\n    public $queue = 'my-custom-queue';\n}\n```\n\n```php\ndispatch(new MyCustomJobClass(auth()-\u003euser()));\n```\n\n### Events\n\n#### PersonalDataSelected\n\nThis event will be fired after the personal data has been selected. It has two public properties:\n- `$personalData`: an instance of `PersonalData`. In your listeners you can call the `add`, `addFile` methods on this object to add extra content to the zip.\n- `$user`: the user for which this personal data has been selected.\n\n#### PersonalDataExportCreated\n\nThis event will be fired after the personal data zip has been created. It has two public properties:\n- `$zipFilename`: the name of the zip filename.\n- `$user`: the user for which this zip has been created.\n\n#### PersonalDataExportDownloaded\n\nThis event will be fired after the export has been download. It has two public properties:\n- `$zipFilename`: the name of the zip filename.\n- `$user`: the user for which this zip has been created.\n\nYou could use this event to immediately clean up the downloaded zip.\n\n## Testing\n\nYou can run all tests by issuing this command:\n\n``` bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-personal-data-export","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-personal-data-export","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-personal-data-export/lists"}