Skip to main content

Command Palette

Search for a command to run...

How to implement soft delete in Laravel?

Updated
1 min read
How to implement soft delete in Laravel?
R

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference

Implementing soft delete in Laravel allows you to "softly" delete records from your database by marking them as deleted instead of physically removing them. This can be useful for scenarios where you want to retain data for auditing or potential restoration. Laravel provides built-in support for soft deletes using Eloquent models.

By using the SoftDeletes trait, Laravel will automatically handle soft deletions for this model.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class YourModel extends Model
{
    use SoftDeletes;
}

More from this blog

R

Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer

157 posts

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, ExpressJS, MySQL, MongoDB. Love collaborating & making a difference