Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Soft Deletes: Safe Data Removal

Implement soft deletes to safely remove data while keeping recovery options.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Enable Soft Deletes
  2. Migration
  3. Query Soft Deleted
  4. Restore and Force Delete

Safe deletion with soft deletes:

Enable Soft Deletes

php
use SoftDeletes;

protected $dates = ['deleted_at'];

Migration

php
$table->softDeletes();

Query Soft Deleted

php
$trashedPosts = Post::onlyTrashed()->get();
$allPosts = Post::withTrashed()->get();

Restore and Force Delete

php
$post->restore();
$post->forceDelete();
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read