..
This commit is contained in:
@@ -4,66 +4,61 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Validator;
|
||||
|
||||
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
||||
use Hyperf\Validation\Validator;
|
||||
use Aether\AetherValidator;
|
||||
|
||||
class CampusValidator
|
||||
class CampusValidator extends AetherValidator
|
||||
{
|
||||
public function __construct(protected ValidatorFactoryInterface $validationFactory)
|
||||
protected function scenes(): array
|
||||
{
|
||||
}
|
||||
|
||||
public function validateCreate(array $data): Validator
|
||||
{
|
||||
return $this->validationFactory->make($data, [
|
||||
'name' => 'required|string|max:255',
|
||||
'parent_id' => 'required|integer|min:0',
|
||||
'level' => 'required|integer|in:1,2,3',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'address' => 'nullable|string|max:500',
|
||||
'contact_phone' => 'nullable|string|max:20',
|
||||
'contact_person' => 'nullable|string|max:20',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
], [
|
||||
'name.required' => '校区名称不能为空',
|
||||
'parent_id.required' => '父级ID不能为空',
|
||||
'level.required' => '层级不能为空',
|
||||
'level.in' => '层级只能是1、2、3',
|
||||
]);
|
||||
}
|
||||
|
||||
public function validateUpdate(array $data): Validator
|
||||
{
|
||||
return $this->validationFactory->make($data, [
|
||||
'id' => 'required|integer|min:1',
|
||||
'name' => 'nullable|string|max:255',
|
||||
'parent_id' => 'nullable|integer|min:0',
|
||||
'level' => 'nullable|integer|in:1,2,3',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'address' => 'nullable|string|max:500',
|
||||
'contact_phone' => 'nullable|string|max:20',
|
||||
'contact_person' => 'nullable|string|max:20',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
], [
|
||||
'id.required' => '校区ID不能为空',
|
||||
'level.in' => '层级只能是1、2、3',
|
||||
]);
|
||||
}
|
||||
|
||||
public function validateQuery(array $data): Validator
|
||||
{
|
||||
return $this->validationFactory->make($data, [
|
||||
'id' => 'nullable|integer|min:1',
|
||||
'name' => 'nullable|string|max:255',
|
||||
'parent_id' => 'nullable|integer|min:0',
|
||||
'level' => 'nullable|integer|in:1,2,3',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'page' => 'nullable|integer|min:1',
|
||||
'size' => 'nullable|integer|min:1|max:100',
|
||||
]);
|
||||
return [
|
||||
'create' => [
|
||||
'rules' => [
|
||||
'name' => 'required|string|max:255',
|
||||
'parent_id' => 'required|integer|min:0',
|
||||
'level' => 'required|integer|in:1,2,3',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'address' => 'nullable|string|max:500',
|
||||
'contact_phone' => 'nullable|string|max:20',
|
||||
'contact_person' => 'nullable|string|max:20',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
],
|
||||
'messages' => [
|
||||
'name.required' => '校区名称不能为空',
|
||||
'parent_id.required' => '父级ID不能为空',
|
||||
'level.required' => '层级不能为空',
|
||||
'level.in' => '层级只能是1、2、3',
|
||||
]
|
||||
],
|
||||
'update' => [
|
||||
'rules' => [
|
||||
'id' => 'required|integer|min:1',
|
||||
'name' => 'nullable|string|max:255',
|
||||
'parent_id' => 'nullable|integer|min:0',
|
||||
'level' => 'nullable|integer|in:1,2,3',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'address' => 'nullable|string|max:500',
|
||||
],
|
||||
'messages' => [
|
||||
'id.required' => '校区ID不能为空',
|
||||
'level.in' => '层级只能是1、2、3',
|
||||
]
|
||||
],
|
||||
'query' => [
|
||||
'rules' => [
|
||||
'id' => 'nullable|integer|min:1',
|
||||
'name' => 'nullable|string|max:255',
|
||||
'parent_id' => 'nullable|integer|min:0',
|
||||
'level' => 'nullable|integer|in:1,2,3',
|
||||
'province' => 'nullable|string|max:100',
|
||||
'city' => 'nullable|string|max:100',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
],
|
||||
'messages' => [
|
||||
'level.in' => '层级只能是1、2、3',
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,74 +4,62 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Validator;
|
||||
|
||||
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
||||
use Hyperf\Validation\Validator;
|
||||
use Aether\AetherValidator;
|
||||
|
||||
class TeacherValidator
|
||||
class TeacherValidator extends AetherValidator
|
||||
{
|
||||
public function __construct(protected ValidatorFactoryInterface $validationFactory)
|
||||
protected function scenes(): array
|
||||
{
|
||||
}
|
||||
|
||||
public function validateCreate(array $data): Validator
|
||||
{
|
||||
return $this->validationFactory->make($data, [
|
||||
'name' => 'required|string|max:50',
|
||||
'age' => 'nullable|integer|min:18|max:65',
|
||||
'gender' => 'nullable|integer|in:1,2',
|
||||
'avatar' => 'nullable|url|max:255',
|
||||
'title' => 'nullable|string|max:100',
|
||||
'major_subject' => 'required|string|max:100',
|
||||
'teaching_style' => 'nullable|string',
|
||||
'introduction' => 'nullable|string',
|
||||
'campus_id' => 'nullable|integer|min:0',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
], [
|
||||
'name.required' => '教师姓名不能为空',
|
||||
'major_subject.required' => '主讲科目不能为空',
|
||||
'age.min' => '年龄不能小于18岁',
|
||||
'age.max' => '年龄不能大于65岁',
|
||||
'gender.in' => '性别只能是1(男)或2(女)',
|
||||
'avatar.url' => '头像必须是有效的URL',
|
||||
]);
|
||||
}
|
||||
|
||||
public function validateUpdate(array $data): Validator
|
||||
{
|
||||
return $this->validationFactory->make($data, [
|
||||
'id' => 'required|integer|min:1',
|
||||
'name' => 'nullable|string|max:50',
|
||||
'age' => 'nullable|integer|min:18|max:65',
|
||||
'gender' => 'nullable|integer|in:1,2',
|
||||
'avatar' => 'nullable|url|max:255',
|
||||
'title' => 'nullable|string|max:100',
|
||||
'major_subject' => 'nullable|string|max:100',
|
||||
'teaching_style' => 'nullable|string',
|
||||
'introduction' => 'nullable|string',
|
||||
'campus_id' => 'nullable|integer|min:0',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
], [
|
||||
'id.required' => '教师ID不能为空',
|
||||
'age.min' => '年龄不能小于18岁',
|
||||
'age.max' => '年龄不能大于65岁',
|
||||
'gender.in' => '性别只能是1(男)或2(女)',
|
||||
'avatar.url' => '头像必须是有效的URL',
|
||||
]);
|
||||
}
|
||||
|
||||
public function validateQuery(array $data): Validator
|
||||
{
|
||||
return $this->validationFactory->make($data, [
|
||||
'id' => 'nullable|integer|min:1',
|
||||
'name' => 'nullable|string|max:50',
|
||||
'campus_id' => 'nullable|integer|min:0',
|
||||
'major_subject' => 'nullable|string|max:100',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'page' => 'nullable|integer|min:1',
|
||||
'size' => 'nullable|integer|min:1|max:100',
|
||||
'keyword' => 'nullable|string|max:100',
|
||||
]);
|
||||
return [
|
||||
'create' => [
|
||||
'rules' => [
|
||||
'name' => 'required|string|max:50',
|
||||
'age' => 'nullable|integer|min:18|max:65',
|
||||
'gender' => 'nullable|integer|in:1,2',
|
||||
'avatar' => 'nullable|url|max:255',
|
||||
'title' => 'nullable|string|max:100',
|
||||
'major_subject' => 'required|string|max:100',
|
||||
'teaching_style' => 'nullable|string',
|
||||
'introduction' => 'nullable|string',
|
||||
],
|
||||
'messages' => [
|
||||
'name.required' => '教师姓名不能为空',
|
||||
'major_subject.required' => '主讲科目不能为空',
|
||||
'age.min' => '年龄不能小于18岁',
|
||||
'age.max' => '年龄不能大于65岁',
|
||||
'gender.in' => '性别只能是1(男)或2(女)',
|
||||
'avatar.url' => '头像必须是有效的URL',
|
||||
]
|
||||
],
|
||||
'update' => [
|
||||
'rules' => [
|
||||
'id' => 'required|integer|min:1',
|
||||
'name' => 'nullable|string|max:50',
|
||||
'age' => 'nullable|integer|min:18|max:65',
|
||||
'gender' => 'nullable|integer|in:1,2',
|
||||
'avatar' => 'nullable|url|max:255',
|
||||
'title' => 'nullable|string|max:100',
|
||||
'major_subject' => 'nullable|string|max:100',
|
||||
],
|
||||
'messages' => [
|
||||
'id.required' => '教师ID不能为空',
|
||||
'age.min' => '年龄不能小于18岁',
|
||||
'age.max' => '年龄不能大于65岁',
|
||||
'gender.in' => '性别只能是1(男)或2(女)',
|
||||
'avatar.url' => '头像必须是有效的URL',
|
||||
]
|
||||
],
|
||||
'query' => [
|
||||
'rules' => [
|
||||
'id' => 'nullable|integer|min:1',
|
||||
'name' => 'nullable|string|max:50',
|
||||
'campus_id' => 'nullable|integer|min:0',
|
||||
'major_subject' => 'nullable|string|max:100',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'page' => 'nullable|integer|min:1',
|
||||
'size' => 'nullable|integer|min:1|max'
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user