+----------------------------------------------------------------------------------------------- */ namespace app\user\validate; use think\Validate; use think\facade\Db; class RewardsCateValidate extends Validate { // 自定义验证规则 protected function checkOne($value,$rule,$data=[]) { $count = Db::name('RewardsCate')->where([['title','=',$data['title']],['id','<>',$data['id']]])->count(); return $count == 0 ? true : false; } protected $rule = [ 'title' => 'require|checkOne', 'id' => 'require', ]; protected $message = [ 'title.require' => '名称不能为空', 'title.checkOne' => '同样的名称已经存在', 'id.require' => '缺少更新条件', ]; protected $scene = [ 'add' => ['title'], 'edit' => ['title', 'id'], ]; }