Delete Guard
CommunityPrevent unsafe deletions in Filament by enforcing deletion rules at the model level and showing a friendly Filament notification when deletion is blocked.
Author:
Jose Antonio Rojas
Package health
BetaAutomated checks of this plugin's Composer package
15 checks
- Skipped: GitHub Actions pinned to SHA
- Skipped: GitLab CI includes pinned to SHA
- Passed: Open security advisories
- Passed: Dependabot PR responsiveness — No open Dependabot PRs.
- Skipped: Renovate MR responsiveness
- Skipped: Dependabot or Renovate configured
- Skipped: Dependency update cooldown configured
- Failed: Provides a security policy — View details on Plumb
- Passed: Abandoned or archived — No consulted source marks the package abandoned (packagist, github).
- Warning: Commit and release recency — Low activity: last commit 177 days ago; last release 181 days ago.
-
Passed:
composer.lock not committed by library
—
composer.lockis absent from the released dist archive. - Passed: Dist archive is lean
-
Passed:
Current Laravel version supported
—
Package dependencies resolve together with current Laravel
13.0. -
Passed:
Current PHP version supported
—
Constraint
^8.2supports current PHP8.5. - Skipped: Current Symfony version supported
filament/
namespace. Review the source and install at your own risk. Found
malware or an unresolved security issue the author won't
address?
Report it
.
Documentation
- What does it do?
- Installation
- Usage
- Filament integration
- How it works internally
- Translations
- License
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?
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
CannotDeleteModelExceptionto block deletion. - Filament integration that customizes
DeleteActionto:- disable the action (optional),
- show a tooltip (optional),
- attempt
$record->delete()and, if blocked, show a Filament notification.
#Installation
composer require joserojasrodriguez/filament-delete-guard
The package automatically registers its service provider (Laravel package discovery).
#Usage
#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
deletinghook in your model. TheInteractsWithPreventDeletiontrait handles it automatically.
#Filament integration
Filament integration globally configures the delete action:
- Calls
$record->delete()and catchesCannotDeleteModelException. - If the exception occurs, shows a Filament notification with:
- title:
filament-delete-guard::messages.deletion_prevented - body: the exception message
- title:
#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
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
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
The package ships translations for:
filament-delete-guard::messages.deletion_preventedfilament-delete-guard::messages.has_relation
Default messages (en):
- Deletion blocked
- Cannot delete because it has :relation associated.
#License
MIT
Featured Plugins
A selection of plugins curated by the Filament team
Compact Theme
A theme that makes data-heavy panels easier to scan by fitting more useful information on each screen.
Filament
Advanced Tables (formerly Filter Sets)
Supercharge your tables with powerful features like user-customizable views, quick filters, multi-column sorting, advanced table searching, convenient view management, and more. Compatible with Resource Panel Tables, Relation Managers, Table Widgets, and Table Builder!
Kenneth Sese
Spotlight Pro
Browse your Filament Panel with ease. Filament Spotlight Pro adds a Spotlight like Command Palette to your Filament Panel.
Dennis Koch