Laravel soft deletes: delete, restore and query trashed records
PHP Dasun Kalupahana 50 views
<?php
// migration
$table->softDeletes();
// model
use Illuminate\Database\Eloquent\SoftDeletes;
class Post extends Model
{
use SoftDeletes;
}
// usage
$post->delete(); // sets deleted_at
Post::withTrashed()->get(); // include deleted
Post::onlyTrashed()->restore(); // restore deleted
$post->forceDelete(); // remove permanently
Marks a row as deleted instead of removing it, so you can restore it later. withTrashed() and onlyTrashed() let you query deleted rows.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
PHP
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
9 min read
Docker
Docker Build Too Slow? 10 Ways to Speed It Up
A slow Docker build usually has one of a few causes: you...
8 min read