PHPackages                             joserojasrodriguez/filament-delete-guard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. joserojasrodriguez/filament-delete-guard

ActiveLibrary[Security](/categories/security)

joserojasrodriguez/filament-delete-guard
========================================

Prevent deletion of Eloquent models in Filament with automatic notifications and UI protection.

1.1.0(5mo ago)3679↑209.1%1MITPHPPHP ^8.2

Since Feb 26Pushed 5mo agoCompare

[ Source](https://github.com/joserojasrodriguez/filament-delete-guard)[ Packagist](https://packagist.org/packages/joserojasrodriguez/filament-delete-guard)[ RSS](/packages/joserojasrodriguez-filament-delete-guard/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

filament-delete-guard
=====================

[](#filament-delete-guard)

[![Packagist Version](https://camo.githubusercontent.com/2ff2b9f8fadb4c02432f0d44ab018e0cdd5d34c452c24614556b1fa042c64cd6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7365726f6a6173726f6472696775657a2f66696c616d656e742d64656c6574652d6775617264)](https://packagist.org/packages/joserojasrodriguez/filament-delete-guard)[![Packagist Downloads](https://camo.githubusercontent.com/f34a9b1932f96fcb49ecae1919905a9251dc34e29e2cd45b94014efda5656a2e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7365726f6a6173726f6472696775657a2f66696c616d656e742d64656c6574652d6775617264)](https://packagist.org/packages/joserojasrodriguez/filament-delete-guard)[![License](https://camo.githubusercontent.com/f08ba0259edeca5108445a725154f75e1cc859546910d2a906529048bb842174/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6f7365726f6a6173726f6472696775657a2f66696c616d656e742d64656c6574652d6775617264)](https://opensource.org/licenses/MIT)

Prevent unsafe deletions in Filament by enforcing deletion rules at the **model** level and showing friendly notifications when deletion is blocked.

---

What does it do?
----------------

[](#what-does-it-do)

This package provides:

- A small **contract** (`HasPreventDeletion`) to describe deletion rules.
- A **trait** (`InteractsWithPreventDeletion`) with the core logic to validate relations and custom rules.
- A `CannotDeleteModelException` to block deletion.
- Filament integration that **customizes `DeleteAction`** to:
    - disable the action (optional),
    - show a tooltip (optional),
    - attempt `$record->delete()` and, if blocked, show a Filament notification.

---

Installation
------------

[](#installation)

```
composer require joserojasrodriguez/filament-delete-guard
```

The package automatically registers its service provider (Laravel package discovery).

---

Usage
-----

[](#usage)

### 1) Implement the contract and use the trait

[](#1-implement-the-contract-and-use-the-trait)

In your Eloquent model:

```
use Illuminate\Database\Eloquent\Model;
use Joserojasrodriguez\FilamentDeleteGuard\Contracts\HasPreventDeletion;
use Joserojasrodriguez\FilamentDeleteGuard\Traits\InteractsWithPreventDeletion;

class Invoice extends Model implements HasPreventDeletion
{
    use InteractsWithPreventDeletion;

    public function deletionRelations(): array
    {
        return [
            // relation method => human label (used in the default message)
            'payments' => 'payments',
            'lines' => 'lines',
        ];
    }

    public function deletionMessages(): array
    {
        return [
            // optional per-relation override
            'payments' => 'You cannot delete an invoice with associated payments.',
        ];
    }

    public function customDeletionRules(): void
    {
        // Optional: add any extra checks here.
        // To block deletion, throw CannotDeleteModelException.
        // throw CannotDeleteModelException::because('This invoice is locked.');
    }
}
```

> **Note:** You do not need to manually add the `deleting` hook in your model. The `InteractsWithPreventDeletion` trait handles it automatically.

---

Filament integration
--------------------

[](#filament-integration)

Filament integration globally configures the delete action:

- Calls `$record->delete()` and catches `CannotDeleteModelException`.
- If the exception occurs, shows a Filament notification with:
    - title: `filament-delete-guard::messages.deletion_prevented`
    - body: the exception message

### BulkActions support

[](#bulkactions-support)

The package works with Filament `DeleteBulkAction`.

Each record deletion is executed individually, so the `deleting` event is triggered for every model. If a record throws `CannotDeleteModelException`, Filament counts it as a failed deletion and continues processing the remaining records.

Partial success notifications are automatically handled by Filament.

### Optional: Disable the delete action and show tooltip

[](#optional-disable-the-delete-action-and-show-tooltip)

If your model implements these methods, the delete action can be disabled and display a tooltip:

```
public function showDeleteAction(): bool
{
    return false; // disables the delete action
}

public function showDeleteActionMessage(): ?string
{
    return 'Cannot delete because it is reconciled.'; // tooltip text
}
```

> These methods are checked at runtime by the Filament action configuration.

---

How it works internally
-----------------------

[](#how-it-works-internally)

The trait registers a model `deleting` event using Laravel’s trait booting convention:

```
protected static function bootInteractsWithPreventDeletion(): void
{
    static::deleting(fn ($model) => $model->ensureCanBeDeleted());
}
```

---

Translations
------------

[](#translations)

The package ships translations for:

- `filament-delete-guard::messages.deletion_prevented`
- `filament-delete-guard::messages.has_relation`

Default messages (en):

- **Deletion blocked**
- **Cannot delete because it has :relation associated.**

---

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance71

Regular maintenance activity

Popularity23

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a57ba4d87ba32c699b97d0a802231e122d59d756a2e740411af51550f47b6e1a?d=identicon)[joserojasrodriguez](/maintainers/joserojasrodriguez)

### Embed Badge

![Health badge](/badges/joserojasrodriguez-filament-delete-guard/health.svg)

```
[![Health](https://phpackages.com/badges/joserojasrodriguez-filament-delete-guard/health.svg)](https://phpackages.com/packages/joserojasrodriguez-filament-delete-guard)
```

###  Alternatives

[backstage/mails

View logged mails and events in a beautiful Filament UI.

16429.7k](/packages/backstage-mails)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

85240.3k9](/packages/stephenjude-filament-two-factor-authentication)[marcelweidum/filament-passkeys

Use passkeys in your filamentphp app

6758.2k2](/packages/marcelweidum-filament-passkeys)[visualbuilder/email-templates

Email Template editor for Filament

11753.1k](/packages/visualbuilder-email-templates)[finity-labs/fin-mail

A powerful email template manager and composer for Filament with dynamic token replacement, template versioning, and inline email sending.

316.8k2](/packages/finity-labs-fin-mail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
