Download the PHP package tuzelko/yii2-softdelete without Composer

On this page you can find all versions of the php package tuzelko/yii2-softdelete. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-softdelete

Yii2 Soft-Delete extension

Project Status: Active Tests Latest Version PHP Version Total Downloads License

Soft-delete extension for the Yii2 framework.

Adds soft-delete (and restore) behaviour to any ActiveRecord model via a single PHP trait, with an accompanying query class that automatically hides deleted records from all queries.

Features

Requirements

Installation

Quick start

1. Add the column to your migration

2. Apply the trait to your model

That's it. Post::find() now returns only non-deleted records, and $post->delete() soft-deletes instead of hard-deletes.

Column strategies

Override softDeleteColumn() and softDeleteType() when the defaults do not fit your schema.

Constant Column value when deleted Column value when restored
TYPE_TIMESTAMP_INT (default) time() (Unix timestamp) NULL
TYPE_TIMESTAMP_DB NOW() / datetime('now') / etc. NULL
TYPE_BOOL 1 0
TYPE_TIMESTAMP_INT_ZERO time() (Unix timestamp) 0

TYPE_TIMESTAMP_INT_ZERO keeps the deletion timestamp like TYPE_TIMESTAMP_INT, but stores 0 instead of NULL for non-deleted rows. Use it when the column must be part of a UNIQUE index: most engines exclude NULL from uniqueness checks, so a plain timestamp column lets duplicate "live" rows slip through — 0 does not.

Instance methods

delete() is a routing method — by default it calls softDelete(). See Default delete routing to change this.

Deprecated: forceDelete() is a deprecated alias for hardDelete().

Query scopes

Bulk operations

deleteAll() is a routing method — by default it calls softDeleteAll(). See Default delete routing to change this.

Deprecated: forceDeleteAll() is a deprecated alias for hardDeleteAll().

Auto-scope behaviour: softDeleteAll(), updateAll(), and restoreAll() automatically add a "not deleted" (or "deleted") condition unless your $condition already references the soft-delete column. This prevents double-applying the scope when you target records explicitly.

Default delete routing

defaultDeleteMethod() controls what delete() and deleteAll() do. Override it in your model to change the behaviour:

Constant delete() behaviour deleteAll() behaviour
DELETE_METHOD_SOFT (default) calls softDelete() calls softDeleteAll()
DELETE_METHOD_HARD calls hardDelete() calls hardDeleteAll()
DELETE_METHOD_DISABLED throws NotSupportedException throws NotSupportedException

Relations

Because SoftDeleteTrait overrides find() to return a SoftDeleteActiveQuery, the soft-delete scope is automatically applied to every relation that points to a soft-delete-enabled model — including eager loading via with() and join-based loading via joinWith().

Declaring relations

Eager loading with with()

JOIN-based loading with joinWith()

Both models' soft-delete scopes are applied automatically. The condition for each model is placed in the JOIN's ON clause (not WHERE), which preserves correct LEFT JOIN semantics: a user with no active posts still appears with NULL post columns rather than disappearing.

Column names are always table-qualified (post.deleted_at), so joining two tables that both have a soft-delete column never produces an "ambiguous column" SQL error.

The relation callback works the same as with with():

Events

All four events receive a yii\base\ModelEvent. Setting $event->isValid = false in a before* handler cancels the operation.

Constant When
SoftDeleteTrait::EVENT_BEFORE_SOFT_DELETE Before softDelete() writes to the DB
SoftDeleteTrait::EVENT_AFTER_SOFT_DELETE After softDelete() succeeds
SoftDeleteTrait::EVENT_BEFORE_RESTORE Before restore() writes to the DB
SoftDeleteTrait::EVENT_AFTER_RESTORE After restore() succeeds

hardDelete() fires the standard Yii2 ActiveRecord::EVENT_BEFORE_DELETE / EVENT_AFTER_DELETE events.

Performance

Add an index on the soft-delete column so that the automatic scope does not cause a full-table scan:

Without the index every find(), softDeleteAll(), updateAll(), and restoreAll() call will scan the whole table once it grows large.

Cascade soft-deletes

Soft-deleting a parent record does not automatically soft-delete its children. If you need cascading behaviour, implement it in the afterSoftDelete hook:

String conditions and auto-scope

softDeleteAll(), updateAll(), and restoreAll() automatically add a soft-delete scope unless your $condition already references the soft-delete column. This detection works for array conditions only. Plain SQL strings are not inspected.

If you pass a raw string that already targets the soft-delete column, wrap it in an array to prevent the scope from being added twice:

Running tests

Tests run inside Docker (PHP 8.3 + SQLite) with no local setup required.

License

MIT — see LICENSE.


All versions of yii2-softdelete with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
yiisoft/yii2 Version ~2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tuzelko/yii2-softdelete contains the following files

Loading the files please wait ...