AppIconCate.php 752 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AppIconCate extends Validate{
  6. protected $rule = [
  7. 'name|名称' => 'require|checkUnique|length:1,20',
  8. ];
  9. protected $message = [
  10. 'name.length' => '名称必须20字以内',
  11. ];
  12. protected $scene = [
  13. ];
  14. // 自定义验证规则
  15. protected function checkUnique($value,$rule,$data=[])
  16. {
  17. $info = Db::name('app_icon_cate')->where('name',$data['name'])->where('del',0)->find();
  18. if($data['id'] <= 0 && $info){
  19. return '名称已被使用';
  20. }
  21. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  22. return '名称已被使用';
  23. }
  24. return true;
  25. }
  26. }