PHPackages                             yiithings/yii2-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. [Framework](/categories/framework)
4. /
5. yiithings/yii2-softdelete

Abandoned → [yiithings/yii2-softdelete](/?search=yiithings%2Fyii2-softdelete)Yii2-extension[Framework](/categories/framework)

yiithings/yii2-softdelete
=========================

Soft delete extension for Yii2 framework

716.2k—6.7%4PHP

Since Sep 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/yiithings/yii2-softdelete)[ Packagist](https://packagist.org/packages/yiithings/yii2-softdelete)[ RSS](/packages/yiithings-yii2-softdelete/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 SoftDelete
===============

[](#yii2-softdelete)

[![Build Status](https://camo.githubusercontent.com/556411a3a2c65fdfe3da0cf9c6131400ad59a12e8cd7e3c7f6e9189c41affa87/68747470733a2f2f7472617669732d63692e6f72672f7969697468696e67732f796969322d736f667464656c6574652e737667)](https://travis-ci.org/yiithings/yii2-softdelete)[![Latest Stable Version](https://camo.githubusercontent.com/323d4eec4a79b0d2213e10f83eb2f9b1b7ee27966e24aff95cad7966cfc2dd68/68747470733a2f2f706f7365722e707567782e6f72672f7969697468696e67732f796969322d736f667464656c6574652f762f737461626c652e737667)](https://packagist.org/packages/yiithings/yii2-softdelete)[![Total Downloads](https://camo.githubusercontent.com/e8fb5e22a4255cf4e654afe2553534120b8d06591d0e177f6c0dac10bf075ef4/68747470733a2f2f706f7365722e707567782e6f72672f7969697468696e67732f796969322d736f667464656c6574652f646f776e6c6f6164732e737667)](https://packagist.org/packages/yiithings/yii2-softdelete)[![Latest Unstable Version](https://camo.githubusercontent.com/18eb3676dec77878ab048c50e0896583a0398083bd2cac3c4e40021bfb0595db/68747470733a2f2f706f7365722e707567782e6f72672f7969697468696e67732f796969322d736f667464656c6574652f762f756e737461626c652e737667)](https://packagist.org/packages/yiithings/yii2-softdelete)[![License](https://camo.githubusercontent.com/111866bd8340860fa6856892bf38d5f11d37db39ea28ae79a775108953abe3e5/68747470733a2f2f706f7365722e707567782e6f72672f7969697468696e67732f796969322d736f667464656c6574652f6c6963656e73652e737667)](https://packagist.org/packages/yiithings/yii2-softdelete)

Soft delete extension for Yii2 framework.

This extension ensures that soft-deleted has delete native consistent behavior and is IDE-friendly.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yiithings/yii2-softdelete "*"

```

or add

```
"yiithings/yii2-softdelete": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

Edit model class:

```
use yiithings\softdelete\behaviors\SoftDeleteBehavior;
use yiithings\softdelete\SoftDelete;

class Model extends \yii\db\ActiveRecord
{
    use SoftDelete;

    public function behaviors()
    {
        return [
            'class' => SoftDeleteBehavior::className(),
        ];
    }
}
```

Change database table structures, add `deleted_at (int 11)` field and attached to UNIQUE index.

API
---

[](#api)

### ActiveRecord class (SoftDelete Trait):

[](#activerecord-class-softdelete-trait)

find系列方法会返回 `yiithings\softdelete\ActiveQuery` 对象。

- softDelete() 使用软删除模式删除数据
- forceDelete() 使用物理删除模式强制删除数据
- restore() 恢复被软删除的模型数据
- isTrashed() 是否被软删除

以下命令分别是 `find()` / `findOne()` / `findAll()` 在不同模式下的对应版本：

所有模型（包括被软删除的）：

- findWithTrashed()
- findOneWithTrashed($condition)
- findAllWithTrashed($condition)

只查找被软删除的模型：

- findOnlyTrashed()
- findOneOnlyTrashed($condition)
- findAllOnlyTrashed($condition)

以下的命令均被重写成软删除版本：

- find()
- findOne()
- findAll()
- delete()

### yiithings\\softdelete\\ActiveQuery

[](#yiithingssoftdeleteactivequery)

增加了 `withTrashed()`, `withoutTrashed()` 和 `onlyTrashed()` 三个方法， 设置相应的查找模式。

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c79a4220751bab4ff8ee0953a41c4664fddb12e2a47e69442c2e5315b5c7ef9a?d=identicon)[panlatent](/maintainers/panlatent)

---

Top Contributors

[![panlatent](https://avatars.githubusercontent.com/u/4393268?v=4)](https://github.com/panlatent "panlatent (5 commits)")[![terranc](https://avatars.githubusercontent.com/u/224353?v=4)](https://github.com/terranc "terranc (1 commits)")

---

Tags

active-recorddbmodelmysqlsoftdev1yii2

### Embed Badge

![Health badge](/badges/yiithings-yii2-softdelete/health.svg)

```
[![Health](https://phpackages.com/badges/yiithings-yii2-softdelete/health.svg)](https://phpackages.com/packages/yiithings-yii2-softdelete)
```

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M298](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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