GalleryCateValidate.php 725 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. namespace app\admin\validate;
  8. use think\Validate;
  9. use think\facade\Db;
  10. class GalleryCateValidate extends Validate
  11. {
  12. // 自定义验证规则
  13. protected function checkOne($value,$rule,$data=[])
  14. {
  15. $count = Db::name('GalleryCate')->where([['title','=',$data['title']],['id','<>',$data['id']],['delete_time','=',0]])->count();
  16. return $count == 0 ? true : false;
  17. }
  18. protected $rule = [
  19. 'title' => 'require|checkOne',
  20. ];
  21. protected $message = [
  22. 'title.require' => '分类名称不能为空',
  23. 'title.checkOne' => '同样的分类名称已经存在',
  24. ];
  25. }