Files
hyperf_data/app/Validator/TeacherValidator.php
Aether 9052c7069f ..
2025-10-16 20:06:23 +08:00

65 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Validator;
use Aether\AetherValidator;
class TeacherValidator extends AetherValidator
{
protected function scenes(): array
{
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',
'teach_subject' => 'nullable|string|max:100',
'style' => 'nullable|string',
'introduction' => 'nullable|string',
],
'messages' => [
'name.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',
'teach_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',
'teach_subject' => 'nullable|string|max:100',
'status' => 'nullable|integer|in:0,1',
'page' => 'nullable|integer|min:1',
'size' => 'nullable|integer|min:1|max',
],
],
];
}
}