Laravel Personal Data Export

Laravel Personal Data Export

Freek Van der Herten released a Spatie package called Laravel Personal Data Export last week to help you create zip files containing personal data in your Laravel applications:

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.

With privacy concerns rising on social media and other web applications, exporting user data might be something you want to consider. As seen in the package’s readme, you configure the file and data export by defining a selectPersonalData method the user model:

// in your User model

public function selectPersonalData(PersonalDataSelection $personalDataSelection) {
        ->add('user.json', ['name' => $this->name, 'email' => $this->email])
        ->addFile('other-user-data.xml', 's3');

The Laravel Personal Data Export package provides configuration for how many days the personal data will be available to the user, along with some other customizable options:

return [
     * The disk where the exports will be stored by default.
    'disk' => 'personal-data-exports',

     * The amount of days the exports will be available.
    'delete_after_days' => 5,

     * Determines whether the user should be logged in to be able
     * to access the export.
    'authentication_required' => true,

     * The mailable which will be sent to the user when the export
     * has been created.
    'mailable' => \Spatie\PersonalDataExport\Mail\PersonalDataExportCreatedMail::class,

This package takes care of the boilerplate of all the tasks involved in initiating the data export and then fulfilling it roughly in the following sequence:

First, the package generates the data when you dispatch a CreatePersonalDataExportJob in the application (a queued job by default).

Next, when the job runs, the exported data is zipped and copied to the configured disk. Finally, the user receives a notification email with the URL to the download.

Almost every piece (if not all) of the export process is customizable. You can check out this package on GitHub at spatie/laravel-personal-data-export.

Filed in: Laravel Packages / packages


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Laravel Senior Developer
Remote, Canada Only
BeMo Academic Consulting
Senior Fullstack Developer / Architect (w/m/d)
Remote / Munich - Germany GmbH
Medior full stack developer (Laravel)
Deventer (or remote) in the Netherlands, Dutch speaking required.
Senior Full Stack PHP Developer (Laravel)
Senior Laravel Developer