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.
77 lines
1.9 KiB
77 lines
1.9 KiB
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateReviewerRequest 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
|
|
{
|
|
/** @var \App\Models\Reviewer|null $reviewer */
|
|
$reviewer = $this->route('reviewer');
|
|
|
|
return [
|
|
'mobile' => [
|
|
'sometimes',
|
|
'nullable',
|
|
'string',
|
|
'max:20',
|
|
'regex:/^1[3-9]\d{9}$/',
|
|
Rule::unique('reviewers', 'mobile')->ignore($reviewer?->id),
|
|
],
|
|
'name' => ['sometimes', 'string', 'max:64'],
|
|
'status' => ['sometimes', 'string', Rule::in(['active', 'disabled'])],
|
|
'username' => [
|
|
'sometimes',
|
|
'string',
|
|
'max:64',
|
|
'regex:/^[A-Za-z0-9._-]+$/',
|
|
Rule::unique('reviewers', 'username')->ignore($reviewer?->id),
|
|
],
|
|
'password' => ['sometimes', 'nullable', 'string', 'min:6', 'max:255'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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 仅可为字母、数字、点、横线或下划线。',
|
|
];
|
|
}
|
|
}
|