'require|checkUnique', // 'budget_id' => 'require|gt:0', 'company_id' => 'require|gt:0', ]; protected $message = [ // 'budget_id.require' => '参数错误', // 'budget_id.gt' => '参数错误', 'company_id.require' => '参数错误', 'company_id.gt' => '参数错误', ]; protected $scene = [ ]; protected function checkUnique($value,$rule,$data=[]) { $info = Db::name('budget_items') ->where('title',$data['title']) // ->where('budget_id',$data['budget_id']) ->where('company_id',$data['company_id']) ->find(); if($data['id'] <= 0 && $info){ return '名称已被占用'; } if($info && $data['id'] > 0 && $info['id'] != $data['id']){ return '名称已被占用'; } return true; } }