PHP code example of wodrow / yii2wsoftdelete
1. Go to this page and download the library: Download wodrow/yii2wsoftdelete library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wodrow / yii2wsoftdelete example snippets
use wodrow\softdelete\SoftDeleteBehavior;
use wodrow\softdelete\SoftDeleteTrait;
class Model extends \yii\db\ActiveRecord
{
use SoftDeleteTrait;
public static function getDeletedAtAttribute()
{
return "deleted_at";
}
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors = ArrayHelper::merge($behaviors, []);
if (static::getDeletedAtAttribute()) {
$behaviors = ArrayHelper::merge($behaviors, [
'soft-delete' => [
'class' => SoftDeleteBehavior::class,
'deletedAtAttribute' => static::getDeletedAtAttribute(),
],
]);
}
return $behaviors;
}
}