12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class AppIconCate extends Validate{
- protected $rule = [
- 'name|名称' => 'require|checkUnique|length:1,20',
- ];
- protected $message = [
- 'name.length' => '名称必须20字以内',
- ];
- protected $scene = [
- ];
- // 自定义验证规则
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('app_icon_cate')->where('name',$data['name'])->where('del',0)->find();
- if($data['id'] <= 0 && $info){
- return '名称已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被使用';
- }
- return true;
- }
- }
|