香洲二院小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
mini_xzey/app/Http/Requests/Patient/CreatePatientRequest.php

99 lines
2.8 KiB

<?php
namespace App\Http\Requests\Patient;
use App\Dictionary\Patient\IdentifyCardType;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class CreatePatientRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array|string>
*/
/**
* 规则
* @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' => '住址',
];
}
}