教师
This commit is contained in:
77
app/Validator/TeacherValidator.php
Normal file
77
app/Validator/TeacherValidator.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Validator;
|
||||
|
||||
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
||||
use Hyperf\Validation\Validator;
|
||||
|
||||
class TeacherValidator
|
||||
{
|
||||
public function __construct(protected ValidatorFactoryInterface $validationFactory)
|
||||
{
|
||||
}
|
||||
|
||||
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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user