harman/filament-disk-cleanup

Clean up the storage on model updates

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/harman/filament-disk-cleanup

v1.0.0 2025-09-01 09:50 UTC

This package is not auto-updated.

Last update: 2026-01-06 10:20:21 UTC


README

This package aims to automatically remove associated files from the storage when a model with an attachment is deleted or updated in Filament. By leveraging Laravel's built-in lifecycle hooks, it ensures that orphaned files are efficiently handled and removed from the disk, reducing disk space consumption and improving overall system performance.

Requirements

  • PHP 8.0+
  • Laravel 11+
  • Filament v3 or v4

Installation

You can install the package via composer:

composer require harman/filament-disk-cleanup

Usage

Use it in the model where you have an attachment. That's all.

It has two methods:

  • Cleanup::delete($model, 'columnName');
  • Cleanup::update($model, 'columnName');

For example : If you have an avatar column where you store the attachment in the User model, you can use it like this:

use Harman\FilamentDiskCleanup\Cleanup;
class User
{
//--
    protected static function booted()
    {
        static::deleted(function (User $user) {
            Cleanup::delete($user, 'avatar');
        });

        static::saved(function (User $user) {
            Cleanup::update($user, 'avatar');
        });
    }
//--
}

It automatically handles array of attachments. For example, if you have a files column where you store the multiple attachments in the Document model, you can use it like this:

use Harman\FilamentDiskCleanup\Cleanup;
class Document
{
//--
    protected static function booted()
    {
        static::deleted(function (Document $document) {
            Cleanup::delete($document, 'files');
        });

        static::saved(function (Document $document) {
            Cleanup::update($document, 'files');
        });
    }
//--
}

No extra configuration is required.

License

The MIT License (MIT). Please see License File for more information.