Handling soft deletes
Creating a resource with soft deletes
By default, you will not be able to interact with deleted records in the admin panel. If you’d like to add functionality to restore, force delete and filter trashed records in your resource, use the--soft-deletes flag when generating the resource:
Adding soft deletes to an existing resource
Alternatively, you may add soft deleting functionality to an existing resource. Firstly, you must update the resource:Deleting records on the List page
By default, you can bulk-delete records in your table. You may also wish to delete single records, using aDeleteAction:
Lifecycle hooks
You can use thebefore() and after() methods to execute code before and after a record is deleted:
Halting the deletion process
At any time, you may call$action->halt() from inside a lifecycle hook or mutation method, which will halt the entire deletion process:
cancel() the action instead of halting it:
Authorization
For authorization, Filament will observe any model policies that are registered in your app. Users may delete records if thedelete() method of the model policy returns true.
They also have the ability to bulk-delete records if the deleteAny() method of the policy returns true. Filament uses the deleteAny() method because iterating through multiple records and checking the delete() policy is not very performant.
Authorizing soft deletes
TheforceDelete() policy method is used to prevent a single soft-deleted record from being force-deleted. forceDeleteAny() is used to prevent records from being bulk force-deleted. Filament uses the forceDeleteAny() method because iterating through multiple records and checking the forceDelete() policy is not very performant.
The restore() policy method is used to prevent a single soft-deleted record from being restored. restoreAny() is used to prevent records from being bulk restored. Filament uses the restoreAny() method because iterating through multiple records and checking the restore() policy is not very performant.