Skip to content

Cleanup ​

The storage helpers delete staged uploads after a successful operation. A failed operation keeps its files for a retry, and uploads that are never submitted stay on disk. Schedule the cleanup command as a safety net for both cases:

php
// In app/Console/Kernel.php or routes/console.php...
use Illuminate\Support\Facades\Schedule;

Schedule::command('form:cleanup-uploads')->hourly();

The command deletes temporary upload directories older than file_uploads.temporary_uploads.lifetime, which defaults to one hour. You may pass another lifetime in seconds:

bash
php artisan form:cleanup-uploads --lifetime=7200

Which Disks Are Swept ​

The command only deletes inertia-forms-upload-* directories on these disks:

  • The file_uploads.temporary_uploads.disk disk. An empty value uses the local staging disk.
  • The file_uploads.direct_to_storage.disk disk. An empty value uses the s3 disk.
  • Every disk listed in file_uploads.cleanup_disks.
  • Every disk passed with the --disk option, which may be repeated.

The command doesn't discover per-field disks from directToStorage('media') or uploadDisk('media') automatically. Add them to file_uploads.cleanup_disks:

php
// config/inertia-forms.php

return [
    'file_uploads' => [
        'cleanup_disks' => ['media', 'documents'],
    ],
];

You may also pass them for one command run with repeated --disk options:

bash
php artisan form:cleanup-uploads --disk=media --disk=documents

Expiration uses the newest file in each directory, so active chunked or multipart uploads remain. One inaccessible disk doesn't prevent the command from sweeping the remaining disks.

For S3-compatible direct-to-storage uploads, also configure bucket lifecycle rules that expire abandoned inertia-forms-upload-* objects and abort incomplete multipart uploads. S3 doesn't show a multipart session as an ordinary object until it completes.