SoftDeletes trait, enabling soft deletion (logical deletion via deleted_at timestamp) while adding customizable restrictions (e.g., business rules, foreign key constraints, or role-based permissions).Deletable trait can be composed with other traits (e.g., SoftDeletes, Timestamps) without conflicts.deleting() and deleting:failed events, allowing for custom logic (e.g., audit logs, cascading checks) before execution.DeletableScope to filter soft-deleted records in queries, useful for audit trails or restored data retrieval.use Deletable; in a model). Advanced features (e.g., custom validation) demand ~5–10 lines of code per model.deleted_at column).Model::forceDelete()).@method bool forceDelete()) and enforce via Policies.deleted_at + is_archived flags) or database partitioning for large datasets.deleted_at to existing tables may require schema migrations in legacy systems.nullable timestamps and backfill via a seed job.deleted_at).deletion_audit table)?deleted_at?forceDelete() be disabled entirely or restricted (e.g., via Policies)?deleted_at column (timestamp, nullable), compatible with all major RDBMS.Order, User, Invoice).use Deletable; to target models.deleted_at columns:
Schema::table('orders', function (Blueprint $table) {
$table->softDeletes();
});
deleting():
protected static function bootDeletable()
{
static::deleting(function (Model $model) {
if ($model->hasPaidPayments()) {
throw new \Exception("Cannot delete paid orders.");
}
});
}
forceDelete():
public function delete(User $user, Model $model)
{
return $user->isAdmin();
}
/admin/orders/trash) to list/restore soft-deleted records.nova-soft-deletes package for UI support.withoutGlobalScopes().User models (e.g., for subscriptions).Log, Draft).Order, Invoice).deleted_at table growth via database metrics (e.g., pg_stat_user_tables).// app/Console/Commands/PurgeSoftDeletes.php
public function handle()
{
Model::where('deleted_at', '<', now()->subDays(30))->forceDelete();
}
deleting:failed events) for debugging.withoutGlobalScopes(SoftDeletes::class) is used in queries.forceDelete().Model::withTrashed()->find($id)->restore()).deleted_at for large tables:
Schema::table('orders', function (Blueprint $table) {
$table->index('deleted_at');
});
deleted_at in PostgreSQL/MySQL for >1M soft-deleted records.$model->newQuery()->where('id', $model->id)->lockForUpdate()->get();
deleted_at is tenant-aware (e.g., `tenantHow can I help you explore Laravel packages today?