Skip to content

Export Purge

This guide explains how to automatically clean up old export files from your storage disk.

Overview

Export files (XLSX, CSV) can accumulate over time and consume storage space. The export package includes a purge command that removes files older than the configured number of days.

Configuration

Configure the purge behavior in config/datatables-export.php:

'purge' => [
// Remove export files older than this many days
'days' => 1,
],

Manual Purge

Run the purge command manually whenever needed:

php artisan datatables:purge-export

Options

  • --days: Override the configured days value for this run
# Purge files older than 7 days
php artisan datatables:purge-export --days=7

Automated Purge (Recommended)

Schedule the purge command to run automatically in routes/console.php:

use Illuminate\Console\Scheduling\Schedule;
 
$schedule->command('datatables:purge-export')->daily();

How It Works

The purge command:

  1. Reads the configured disk from config('datatables-export.disk')
  2. Scans all files on the disk
  3. Identifies files with .xlsx or .csv extensions
  4. Deletes files modified before the configured cutoff date
  5. Outputs progress information

Important Notes

  • The purge only affects export files (.xlsx, .csv)
  • Files from other applications on the same disk are not affected
  • The purge respects the configured storage disk, not the S3 disk
  • Running the command multiple times is safe (idempotent)

Related Documentation