<?php
namespace app\system\validate;
use think\Validate;
class CourseValidate extends Validate
{
protected $rule = [
'grade_id' => 'require|number',
'subject_id' => 'require|number',
'name' => 'require',
'type' => 'require|number',
'week_hour' => 'require|checkWeekHour:每周课时不能小于0',
'locked' => 'number',
'id' => 'number',
];
protected $message = [
'grade_id.require' => '年级ID不能为空!',
'grade_id.number' => '年级ID类型有误!',
'subject_id.require' => '科目ID不能为空!',
'subject_id.number' => '科目ID类型有误!',
'name.require' => '课程名称不能为空!',
'type.require' => '课程类型不能为空!',
'type.number' => '课程类型有误!',
'week_hour.require' => '周课时不能为空!',
'locked.number' => '状态数据有误!',
'id.number' => '数据类型有误!',
];
protected $scene = [
'save' => ['grade_id', 'id', 'subject_id', 'name', 'type', 'week_hour', 'locked'],
];
// 自定义验证规则
protected function checkWeekHour($value,$rule,$data=[],$name,$description){
if ($value <= 0){
return $rule;
}else{
return true;
}
}
}
网友评论