Laravel Soft Deletes Tutorial: Safely Removing Records

Learn how Laravel soft deletes work — mark records as deleted without losing data, restore them, and query trashed records.

Permanently deleting data is risky — what if a user accidentally deletes an important record? Laravel's soft delete feature marks records as deleted without actually removing them from the database, so they can be restored later. How Soft Deletes Work Instead of removing a row, Laravel sets a deleted_at timestamp on it. Any record with a non-null deleted_at is automatically excluded from normal queries — but the data still exists. Step 1: Add the deleted_at Column php artisan make:migration add_soft_deletes_to_products_table --table=products use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; public function up(): void { Schema::table('products', function (Blueprint $table) { $table->softDeletes(); }); } public function down(): void { Schema::table('products', function (Blueprint $table) { $table->dropSoftDeletes(); }); } php artisan migrate Step 2: ...

Home · Projects · Articles · Developer tools · Contact