1
0
Fork 0

更新 app/Admin/Services/KeywordService.php

panliang 2023-09-25 10:27:32 +08:00
parent 57506111ba
commit b84018eb00
1 changed files with 14 additions and 6 deletions

View File

@ -31,14 +31,22 @@ class KeywordService extends BaseService
return ['items' => $this->getTree(request()->all())];
}
public function delete(string $ids): mixed
/**
* 删除的前置方法
*
* @param array $ids 主键id
* @return mixed true: 继续后续操作, string: 中断操作, 返回错误提示
*/
public function preDelete(array $ids)
{
$ids = explode(',', $ids);
if (count($ids) == 1) {
$this->query()->where('path', 'like', '%-'.$ids[0].'-%')->delete();
}
// 删除子级
$this->query()->where(function ($q) use ($ids) {
foreach ($ids as $id) {
$q->orWhere('path', 'like', '%-'.$id.'-%');
}
})->delete();
return $this->query()->whereIn('id', $ids)->delete();
return true;
}
public function validate($data, $id = null)