mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进软删除destroy和restore方法
This commit is contained in:
@@ -77,8 +77,8 @@ trait SoftDelete
|
|||||||
*/
|
*/
|
||||||
public static function destroy($data, $force = false)
|
public static function destroy($data, $force = false)
|
||||||
{
|
{
|
||||||
$model = new static();
|
// 包含软删除数据
|
||||||
$query = $model->db();
|
$query = self::withTrashed();
|
||||||
if (is_array($data) && key($data) !== 0) {
|
if (is_array($data) && key($data) !== 0) {
|
||||||
$query->where($data);
|
$query->where($data);
|
||||||
$data = null;
|
$data = null;
|
||||||
@@ -109,9 +109,13 @@ trait SoftDelete
|
|||||||
public function restore($where = [])
|
public function restore($where = [])
|
||||||
{
|
{
|
||||||
$name = $this->getDeleteTimeField();
|
$name = $this->getDeleteTimeField();
|
||||||
|
if (empty($where)) {
|
||||||
|
$pk = $this->getPk();
|
||||||
|
$where[$pk] = $this->getData($pk);
|
||||||
|
$where[$name] = ['not null', ''];
|
||||||
|
}
|
||||||
// 恢复删除
|
// 恢复删除
|
||||||
return $this->isUpdate()->save([$name => null], $where);
|
return $this->removeWhereField($this->getDeleteTimeField(true))->where($where)->update([$name => null]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user