after(function (Validator $v): void { $routeCompetition = $this->route('competition'); if (! $routeCompetition instanceof Competition) { return; } $openInput = $this->input('signup_open_at'); $closeInput = $this->input('signup_close_at'); $open = $openInput ?? $routeCompetition->signup_open_at?->toIso8601String(); $close = $closeInput ?? $routeCompetition->signup_close_at?->toIso8601String(); if ($open && $close && strtotime((string) $close) < strtotime((string) $open)) { $v->errors()->add( 'signup_close_at', '报名截止时间须不早于开始时间。', ); } }); } /** * @return array */ public function rules(): array { $competition = $this->route('competition'); assert($competition instanceof Competition); return [ 'slug' => [ 'sometimes', 'string', 'max:128', 'regex:/^(?!.*\s)[\p{L}\p{N}\-_·]+$/u', Rule::unique('competitions', 'slug')->ignore($competition->id), ], 'name' => ['sometimes', 'string', 'max:200'], 'description' => ['sometimes', 'nullable', 'string'], 'pledge_content_html' => ['sometimes', 'nullable', 'string', 'max:500000'], 'status' => ['sometimes', 'string', 'max:32', Rule::in(Competition::STATUSES)], 'published' => ['sometimes', 'boolean'], 'signup_open_at' => ['sometimes', 'nullable', 'date'], 'signup_close_at' => ['sometimes', 'nullable', 'date'], 'form_schema_id' => [ 'sometimes', 'nullable', 'integer', Rule::exists('form_schema_definitions', 'id')->where('purpose', FormSchemaDefinition::PURPOSE_SIGNUP), ], 'review_form_schema_id' => [ 'sometimes', 'nullable', 'integer', Rule::exists('form_schema_definitions', 'id')->where('purpose', FormSchemaDefinition::PURPOSE_REVIEW), ], 'branding_json' => ['sometimes', 'nullable', 'array'], 'settings' => ['sometimes', 'nullable', 'array'], 'scoring_rules_json' => ['sometimes', 'nullable', 'array'], ]; } /** * @return array */ public function attributes(): array { return [ 'slug' => '访问地址', ]; } /** * @return array */ public function messages(): array { return [ 'slug.regex' => ':attribute 仅可为中文、字母、数字、横线、下划线或中点,且不能含空格。', ]; } }