<?php
namespace app\admin\validate;
use think\Validate;
class Cate extends Validate
{
protected $rule=[
'catename'=>'unique:cate|require|max:25',
];
protected $message=[
'catename.require'=>'栏目名称不得为空!',
'catename.unique'=>'栏目名称不得重复!',
];
protected $scene=[
'add'=>['catename'],
'edit'=>['catename'],
];
public function checkHasValue($value, $rule) {
$id = input('id');
if (empty($id)) {
$Value = Db::name('cate')->where('catename',$value)->find();
if (empty($Value)) {
return true;
} else {
return "邮箱已存在!";
}
} else {
//更改资料判断栏目名称是否有重复
$checkValue = Db::name('cate')
->where('id','neq',$id)
->where('catename',$value)
->find();
if (empty($checkValue)) {
return true;
} else {
return "邮箱已存在";
}
}
}