12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Http\Requests\Coach;
- use Illuminate\Foundation\Http\FormRequest;
- /**
- * 技师排班设置请求验证
- */
- class SetScheduleRequest extends FormRequest
- {
- /**
- * 判断用户是否有权限进行此请求
- */
- public function authorize(): bool
- {
- return true;
- }
- /**
- * 获取验证规则
- */
- public function rules(): array
- {
- return [
- 'time_ranges' => 'required|array|min:1',
- 'time_ranges.*.start_time' => [
- 'required',
- 'string',
- 'regex:/^([01][0-9]|2[0-3]):[0-5][0-9]$/', // 开始时间保持 00:00-23:59
- ],
- 'time_ranges.*.end_time' => [
- 'required',
- 'string',
- 'regex:/^((?:[01][0-9]|2[0-3]):[0-5][0-9]|24:00)$/', // 结束时间允许 24:00
- ],
- ];
- }
- /**
- * 获取验证错误消息
- */
- public function messages(): array
- {
- return [
- 'time_ranges.required' => '必须设置时间段',
- 'time_ranges.array' => '时间段必须是数组格式',
- 'time_ranges.min' => '至少设置一个时间段',
- 'time_ranges.*.start_time.required' => '开始时间不能为空',
- 'time_ranges.*.start_time.regex' => '开始时间格式错误,应为00:00-23:59格式',
- 'time_ranges.*.end_time.required' => '结束时间不能为空',
- 'time_ranges.*.end_time.regex' => '结束时间格式错误,应为00:00-24:00格式',
- ];
- }
- }
|