['规则1','规则2'...] * * @var array */ protected $rule = [ 'title|名称' => 'require|length:1,20|checkUnique', ]; /** * 定义错误信息 * 格式:'字段名.规则名' => '错误信息' * * @var array */ protected $message = [ ]; protected function checkUnique($value, $rule, $data=[]){ if(isset($data['id']) && $data['id'] > 0){ $ret = Db::name('quality_cate') ->where('del',0) ->where('title',$data['title']) ->where('org_id',$data['org_id']) ->where('pid',$data['pid']) ->where('id','<>',$data['id']) ->find(); }else{ $ret = Db::name('quality_cate') ->where('del',0) ->where('title',$data['title']) ->where('org_id',$data['org_id']) ->where('pid',$data['pid']) ->find(); } return $ret?'名称已被使用':true; } }