*/ /** * 规则 * @return array */ public function rules(): array { return [ 'name' => 'required', 'card_type' => 'required', 'card_no' => ['required', function ($attribute, $value, $fail) { $card_type = getIDCardType($value); switch ($card_type) { // 未知证件,身份证,港澳台社保卡号 case 0: case 1: if (!IdentifyCardType::RESIDENT_ID_CARD->validateNumber($value)) { $fail('证件号码格式错误'); } break; case 2: if (!IdentifyCardType::SOCIAL_SECURITY_CARD->validateNumber($value)) { $fail('证件号码格式错误'); } break; // 2017/2023 版永居证 case 3: case 4: if (!IdentifyCardType::FOREIGNER_PERMANENT_RESIDENCE_PERMIT->validateNumber($value)) { $fail('证件号码格式错误'); } break; } }], 'phone' => ['required', function ($attribute, $value, $fail) { if (!checkMobilePhone($value)) { $fail('联系号码格式错误'); } }], 'birthday' => 'required|date_format:Y-m-d', 'sex' => 'required|in:1,2', // 'nation' => 'max:50', 'address' => 'required|max:100' ]; } /** * 错误提示语句 * @return array */ public function messages(): array { return [ 'sex.required' => '必须选择性别' ]; } /** * 字段名称 * @return array */ public function attributes(): array { return [ 'name' => '名称', 'card_type' => '证件类型', 'card_no' => '证件号码', 'phone' => '联系号码', 'sex' => '性别', 'birthday' => '生日', 'nationality' => '国籍', 'nation' => '民族', 'address' => '住址', ]; } }