PHPackages                             ismayil-dev/epoch-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ismayil-dev/epoch-softdelete

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ismayil-dev/epoch-softdelete
============================

A Laravel package that introduces epoch-based soft deletes to handle unique constraints.

v1.0.0(1y ago)247MITPHPPHP ^8.1CI passing

Since Feb 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ismayil-dev/epoch-softdelete)[ Packagist](https://packagist.org/packages/ismayil-dev/epoch-softdelete)[ Docs](https://github.com/ismayil-dev/epoch-softdelete)[ RSS](/packages/ismayil-dev-epoch-softdelete/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Epoch SoftDelete
================

[](#epoch-softdelete)

A Laravel package that introduces epoch-based soft deletes to handle unique constraints in multi-tenant applications. This package works seamlessly with Laravel's `SoftDeletes` trait, allowing you to enforce unique constraints while using soft deletes without conflicts.

🚀 Features
----------

[](#-features)

- **Better Handling of Unique Constraints**: The epoch-based approach ensures unique constraints are enforced on soft-deleted records without causing conflicts. Users can delete records and recreate them without facing duplicate entry errors.
- **Consistent Developer Experience**: Works just like Laravel's default `SoftDeletes` trait. You only need to adjust the `deleted_at` column type to an integer.
- **Default Value Handling**: Non-deleted records have a default `deleted_at` value of `0`, ensuring clarity and consistency in your database.
- **Backward Compatibility**: The package does not modify any existing features or behaviors, and it fully supports Laravel's soft delete functionality.

📌 Requirements
--------------

[](#-requirements)

- php 8.1+
- Laravel 10, or 11

📥 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require ismayil-dev/epoch-softdelete
```

⚙️ Configuration
----------------

[](#️-configuration)

**Step 1.** Register the Service Provider
After installing the package, you need to manually register the service provider in your Laravel app.
Open `config/app.php` and add the following line inside the `providers` array:

```
'providers' => [
    // Other service providers...
    IsmayilDev\EpochSoftDelete\EpochSoftDeleteServiceProvider::class,
],
```

**Step 2.** Adjust your `deleted_at` column:
For new projects, you can use the built-in macro for migrations:

```
Schema::table('your_table', function (Blueprint $table) {
    $table->epochSoftDeletes();
});
```

**Step 3.** Apply the `EpochSoftDeletes` trait:
In your models, use the EpochSoftDeletes trait instead of the default SoftDeletes trait:

```
use IsmayilDev\EpochSoftDelete\EpochSoftDeletes;

class YourModel extends Model
{
    use EpochSoftDeletes;

    // Other model code...
}
```

**Step 4.** Run migrations:
After modifying your migration files, run the migration to update the database schema:

```
php artisan migrate
```

🛠 Usage
-------

[](#-usage)

Once configured, **continue using Laravel’s soft delete functionality as usual** — no extra changes needed!

```
YourModel::find(1)->delete();
YourModel::withTrashed()->get();
YourModel::onlyTrashed()->get();
YourModel::find(1)->restore();
// etc.
```

### 📌 `deleted_at` Auto-Casting

[](#-deleted_at-auto-casting)

When retrieving soft-deleted models, the `deleted_at` column automatically casts to a **Carbon** instance, making it easier to work with. This means you can perform all Carbon operations on `deleted_at` just like in Laravel’s default soft deletes. 🎯

### ⚙️ Handling Existing Projects

[](#️-handling-existing-projects)

If you're integrating Epoch SoftDelete into an existing project, you must update your existing data before changing the column type.

### Steps to Migrate Existing Projects

[](#steps-to-migrate-existing-projects)

#### 1. Convert existing deleted\_at values:\\

[](#1-convert-existing-deleted_at-values)

If a record has a `deleted_at` date, convert it to an **epoch timestamp**.
If `deleted_at` is `NULL`, update it to `0` to indicate the record is not deleted.

#### 2. Update your database schema:\\

[](#2-update-your-database-schema)

Modify the `deleted_at` column to be an **integer** (epoch timestamp) instead of `timestamp` or `NULL`.

```
Schema::table('your_table', function (Blueprint $table) {
    $table->integer('deleted_at')->default(0)->change();
});
```

#### 3. Apply the EpochSoftDeletes trait in your model.

[](#3-apply-the-epochsoftdeletes-trait-in-your-model)

#### 4. Run migrations to finalize the changes.

[](#4-run-migrations-to-finalize-the-changes)

⚠️ **Important:** If you do not convert your existing `deleted_at` values before running migrations, queries may not work as expected.

🎯 Why Use This Package?
-----------------------

[](#-why-use-this-package)

- Prevents Unique Constraint Conflicts: No duplicate entry errors when re-creating soft-deleted records.
- Zero Learning Curve: Works exactly like Laravel’s default SoftDeletes.
- Ideal for Multi-Tenant &amp; High-Integrity Systems: Ensures smooth database management in complex applications.

📢 Contributing
--------------

[](#-contributing)

We welcome contributions! 🎉

If you find a bug, have a feature request, or want to improve the package:

- Open an issue with details about the problem or feature request.
- Submit a pull request (PR) with improvements or fixes.

Before submitting a PR:

- Make sure your changes follow Laravel and PSR coding standards.
- Run tests to ensure everything works as expected.

Feel free to contribute and help improve Epoch SoftDelete! 🚀

📜 License
=========

[](#-license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance43

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

453d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/89e88803fcbf35fd09f3bb1ce64e73db22a666de6eca2c2ebf332f738cfb5572?d=identicon)[ismayil-dev](/maintainers/ismayil-dev)

---

Top Contributors

[![ismayil-dev](https://avatars.githubusercontent.com/u/35851679?v=4)](https://github.com/ismayil-dev "ismayil-dev (10 commits)")

---

Tags

laravelsoftdeletesoft-deleteepochepoch-softdeleteepoch-based-softdeletelaravel-epoch-softdeletelaravel-softdeletelaravel-soft-deletelaravel-epoch-based-softdeleteismayil-dev

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ismayil-dev-epoch-softdelete/health.svg)

```
[![Health](https://phpackages.com/badges/ismayil-dev-epoch-softdelete/health.svg)](https://phpackages.com/packages/ismayil-dev-epoch-softdelete)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M683](/packages/barryvdh-laravel-ide-helper)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k1](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
