*/ public function rules(): array { $competition = $this->route('competition'); $competitionId = is_object($competition) ? $competition->id : null; return [ 'track_code' => [ 'required', 'string', 'max:64', 'regex:/^(?!.*\s)[\p{L}\p{N}\-_·]+$/u', Rule::unique('competition_tracks', 'track_code')->where('competition_id', $competitionId), ], 'title' => ['required', 'string', 'max:128'], 'description' => ['nullable', 'string', 'max:512'], 'sort' => ['sometimes', 'integer'], 'is_enabled' => ['sometimes', 'boolean'], ]; } /** * @return array */ public function attributes(): array { return [ 'track_code' => '赛道编码', ]; } /** * @return array */ public function messages(): array { return [ 'track_code.regex' => ':attribute 仅可为中文、字母、数字、横线、下划线或中点,且不能含空格。', ]; } }