@devhoussam123 What’s the question?
Yes, if you only want to execute some code when a user is force-deleted, then put it in the forceDeleted method of your observer.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my current implementation, I have the deleted and forceDeleted methods in my UserObserver. These methods are triggered by Laravel's Eloquent model events when a user is deleted or force deleted, respectively.
When I call $user->delete(), Laravel triggers the deleted event, regardless of whether it's a soft delete or a force delete. This means that whenever a user is deleted, either softly or forcefully, the deleted method in my observer is executed.
However, when I explicitly call $user->forceDelete(), Laravel first triggers the deleted event (because it's deleting the record), and then it triggers the forceDeleted event to indicate that the delete operation was forced.
Now, if I want to perform certain actions only when a user is force deleted (and not when it's a soft delete).
<?php
namespace App\Observers;
use App\Models\User;
use App\Notifications\UserDeleted;
use App\Notifications\UserForceDeleted;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit;
class UserObserver implements ShouldHandleEventsAfterCommit
{
/**
* Handle the User "created" event.
*/
public function created(User $user): void
{
//
}
/**
* Handle the User "updated" event.
*/
public function updated(User $user): void
{
//
}
/**
* Handle the User "deleted" event.
*/
public function deleted(User $user): void
{
// Send notification when the user account is deleted.
$user->notify(new UserDeleted());
}
/**
* Handle the User "restored" event.
*/
public function restored(User $user): void
{
//
}
/**
* Handle the User "force deleted" event.
*/
public function forceDeleted(User $user): void
{
// Send notification when the user account is force deleted.
$user->notify(new UserForceDeleted());
}
}
Please or to participate in this conversation.