Skip to main content

SoftDeletes: Archive and Restore Customers

Premium
4 min read

Sometimes, your Customer might get deleted for various reasons, but you might need to recover them months later. In Laravel, it's about SoftDeletes, but in the Filament version, we will show it as an Archived tab with a Restore button:

In this lesson, we will do the following:

  • Add the Archived tab to the Customers table
  • Add Delete button to the table
  • Add the Restore button to the Archived tab
  • Disable row click on the Archived tab

Adding Delete Button

The first thing to do is add the missing Delete button to our form:

app/Filament/Resources/CustomerResource.php

// ...
 
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
 
// ...
])
->bulkActions([
// ...
]);
}
 
// ...

That's it. Now we have a delete button in our table:


Adding Archived Tab

Now that we can delete our customers, we must see them somewhere. Let's add...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 01 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

S
Sjoerd24 ✓ Link copied!

Very helpfull, thank you! Just want to add something: if you also have related records that you want to delete/restore, you can place the following in an observer (or in the model boot):

public function deleted(Device $Device): void
{
// delete also related models
$Device->malfunctions()->delete();
$Device->maintenances()->delete();
}
public function restoring(Device $Device): void
{
$Device->malfunctions()->withTrashed()
->where('deleted_at', '>=', $Device->deleted_at)->restore();
$Device->maintenances()->withTrashed()
->where('deleted_at', '>=', $Device->deleted_at)->restore();
}
```

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.