razonyang /
yii2-app-template
| 1 | <?php |
||
| 2 | namespace App\Model; |
||
| 3 | |||
| 4 | trait SoftDeleteTrait |
||
| 5 | { |
||
| 6 | protected $softDeleteField = 'is_deleted'; |
||
| 7 | |||
| 8 | protected $softDeleteValue = 1; |
||
| 9 | |||
| 10 | public function softDelete() |
||
| 11 | { |
||
| 12 | return $this->updateAttributes([ |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 13 | $this->softDeleteField => $this->softDeleteValue, |
||
| 14 | ]); |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @return bool |
||
| 19 | */ |
||
| 20 | 1 | public function isDeleted(): bool |
|
| 21 | { |
||
| 22 | 1 | $field = $this->softDeleteField; |
|
| 23 | 1 | return $this->$field == $this->softDeleteValue; |
|
| 24 | } |
||
| 25 | } |
||
| 26 |