代码:
public function sceneDelete()
{
return $this->only(['id'])->append('id', 'checkAbleDelete');
}
protected $rule = [
'id' => 'require|checkCategory',
'name' => 'require|unique:'.ArticleCategory::class,
'status' => 'require|in:0,1',
];
protected function checkCategory($value)
{
$category = ArticleCategory::findOrEmpty($value);
if ($category->isEmpty()) {
return '文章分类不存在';
}
return true;
}
protected function checkAbleDelete($value)
{
$hasArticle = ArticleInfo::where(['category_id' => $value])->findOrEmpty();
if (!$hasArticle->isEmpty()) {
return '该分类已被文章使用,暂不可删除';
}
unset($hasArticle);
$hasSon = ArticleCategory::where(['parent_id' => $value])->findOrEmpty();
if (!$hasSon->isEmpty()) {
return '该分类存在子分类,暂不可删除';
}
unset($hasSon);
$dept = ArticleCategory::findOrEmpty($value);
if ($dept['parent_id'] == 0) {
return '顶级分类不可删除';
}
//罪魁祸首
return true;
}
开了调试模式,看了apache日志,没有什么错误,始终不得其解。
最后原因,就是上面代码中的return true的那句话,由于验证方法不规范,验证通过没有返回true,导致内存移除。
排查的时候我把checkAbleDelete的内容全部注释完,都会报内存移除,切记要返回值。