'require|in:article,post', 'id' => 'require|number|checkComment', 'status' => 'require|in:0,1', ]; protected $message = [ 'comment_type.require' => '评论类型不能为空', 'comment_type.in' => '评论类型错误', 'id.require' => '评论id不能为空', 'status.require' => '状态不能为空', ]; public function sceneDelete() { return $this->only(['comment_type', 'id']); } public function sceneStatus() { return $this->only(['comment_type', 'id', 'status']); } public function checkComment($value, $rule, $data) { $commentType = $data['comment_type'] ?? ''; $comment = $commentType === 'article' ? \app\common\model\article\ArticleComment::findOrEmpty($value) : CommunityComment::findOrEmpty($value); if ($comment->isEmpty()) { return '评论不存在'; } return true; } }