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.

67 lines
1.6 KiB

1 month ago
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreReviewerRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
$m = $this->input('mobile');
if ($m === '' || $m === null) {
$this->merge(['mobile' => null]);
}
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'mobile' => [
'nullable',
'string',
'max:20',
'regex:/^1[3-9]\d{9}$/',
Rule::unique('reviewers', 'mobile'),
],
'name' => ['required', 'string', 'max:64'],
'username' => ['required', 'string', 'max:64', 'regex:/^[A-Za-z0-9._-]+$/', Rule::unique('reviewers', 'username')],
'password' => ['required', 'string', 'min:6', 'max:255'],
'status' => ['sometimes', 'string', Rule::in(['active', 'disabled'])],
];
}
/**
* @return array<string, string>
*/
public function attributes(): array
{
return [
'mobile' => '手机号',
'name' => '姓名',
'status' => '状态',
'username' => '账户',
'password' => '密码',
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'username.regex' => ':attribute 仅可为字母、数字、点、横线或下划线。',
];
}
}