PHPackages                             rabnawazak1/laravel-custom-softdelete - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. rabnawazak1/laravel-custom-softdelete

ActiveLibrary[Database &amp; ORM](/categories/database)

rabnawazak1/laravel-custom-softdelete
=====================================

Custom soft delete with is\_deleted, deleted\_at, deleted\_by

040PHP

Since Apr 28Pushed 1mo agoCompare

[ Source](https://github.com/rabnawazak1/laravel-custom-softdelete)[ Packagist](https://packagist.org/packages/rabnawazak1/laravel-custom-softdelete)[ RSS](/packages/rabnawazak1-laravel-custom-softdelete/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Custom SoftDelete
=========================

[](#laravel-custom-softdelete)

[![Latest Version on Packagist](https://camo.githubusercontent.com/89a0a5bc051b5af5bdf9d41843a5f03fa76f6faf9da4dd5a7a8e1687063564bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261626e6177617a616b312f6c61726176656c2d637573746f6d2d736f667464656c6574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rabnawazak1/laravel-custom-softdelete)[![Total Downloads](https://camo.githubusercontent.com/fc29bf67a86acb19053aab7077e6195c347cc151d1b5329fd3763575ae8d5623/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261626e6177617a616b312f6c61726176656c2d637573746f6d2d736f667464656c6574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rabnawazak1/laravel-custom-softdelete)[![License](https://camo.githubusercontent.com/f007c4fca109fcbd293b14a697c5d4c0e89c4d2a1c4eae2f7d2a97e3a1ad7708/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7261626e6177617a616b312f6c61726176656c2d637573746f6d2d736f667464656c6574652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/400ee576a9f339047cc0705ed73e701474dccf2e90dd118292e2c2d082350d9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7261626e6177617a616b312f6c61726176656c2d637573746f6d2d736f667464656c6574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rabnawazak1/laravel-custom-softdelete)

A Laravel package that provides a custom soft delete implementation using three dedicated columns — `is_deleted`, `deleted_at`, and `deleted_by` — giving you full audit-trail awareness of *who* deleted a record, not just *when*.

Unlike Laravel's built-in `SoftDeletes` trait which relies solely on a nullable `deleted_at` column, this package uses a boolean `is_deleted` flag as the primary filter, making it more explicit, index-friendly, and compatible with legacy database schemas or external systems that expect a dedicated status flag.

---

Features
--------

[](#features)

- Three-column soft delete: `is_deleted`, `deleted_at`, `deleted_by`
- Automatically captures the authenticated user's ID on delete
- Global query scope — deleted records are filtered out automatically
- Supports `withTrashed()`, `onlyTrashed()`, `withoutTrashed()` query macros
- `restore()` resets all three columns cleanly
- `forceDelete()` performs a real `DELETE FROM` on the database
- Column names are overridable per model via constants
- Artisan command to generate migrations for any table
- Works with any Eloquent model — apply to as many tables as you want
- No conflicts with Laravel's native `SoftDeletes` trait

---

Requirements
------------

[](#requirements)

DependencyVersionPHP^8.1Laravel^10.0 | ^11.0 | ^12.0 | ^13.0---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require rabnawazak1/laravel-custom-softdelete
```

The package uses Laravel's auto-discovery. The service provider will be registered automatically — no manual setup needed.

---

Database Setup
--------------

[](#database-setup)

### Option A — Artisan Command (Recommended)

[](#option-a--artisan-command-recommended)

Use the built-in Artisan command to generate a migration for any table:

```
php artisan softdelete:add patients
php artisan softdelete:add appointments
php artisan softdelete:add invoices
```

This generates a migration that adds the three columns to your specified table. Run it afterwards:

```
php artisan migrate
```

### Option B — Manual Migration

[](#option-b--manual-migration)

If you prefer to write migrations yourself, add the following columns to your table:

```
Schema::table('your_table', function (Blueprint $table) {
    $table->boolean('is_deleted')->default(0)->index()->after('id');
    $table->timestamp('deleted_at')->nullable()->after('is_deleted');
    $table->unsignedBigInteger('deleted_by')->nullable()->after('deleted_at');
});
```

---

Usage
-----

[](#usage)

### 1. Apply the Trait to a Model

[](#1-apply-the-trait-to-a-model)

```
