61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Customer;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
use Modules\Common\Http\Requests\BaseFormRequest;
|
|
|
|
/**
|
|
* 门店 创建/编辑 验证(登录账号唯一;密码创建必填,编辑留空不修改)
|
|
*/
|
|
class StoreFormRequest extends BaseFormRequest
|
|
{
|
|
protected $stopOnFirstFailure = true;
|
|
|
|
public function rules(): array
|
|
{
|
|
$id = (int) $this->route('id', 0);
|
|
|
|
return [
|
|
'name' => 'required|string|max:100',
|
|
'username' => [
|
|
'required',
|
|
'string',
|
|
'min:4',
|
|
'max:20',
|
|
'alpha_dash',
|
|
Rule::unique('store', 'username')->ignore($id),
|
|
],
|
|
'password' => ($this->isMethod('post') ? 'required' : 'nullable') . '|string|min:6|max:20',
|
|
'level_id' => 'required|integer|exists:customer_level,id',
|
|
'contact' => 'nullable|string|max:50',
|
|
'phone' => 'nullable|string|max:20',
|
|
'address' => 'nullable|string|max:255',
|
|
'payment_cycle_days' => 'nullable|integer|min:0',
|
|
'status' => 'nullable|integer|in:0,1',
|
|
'remark' => 'nullable|string|max:255',
|
|
];
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => '门店名称不能为空',
|
|
'name.max' => '门店名称最长 100 个字符',
|
|
'username.required' => '登录账号不能为空',
|
|
'username.min' => '登录账号至少 4 个字符',
|
|
'username.max' => '登录账号最长 20 个字符',
|
|
'username.alpha_dash' => '登录账号只能由字母、数字、中划线、下划线组成',
|
|
'username.unique' => '登录账号已被使用',
|
|
'password.required' => '登录密码不能为空',
|
|
'password.min' => '登录密码至少 6 位',
|
|
'password.max' => '登录密码最长 20 位',
|
|
'level_id.required' => '请选择客户等级',
|
|
'level_id.exists' => '客户等级不存在',
|
|
'payment_cycle_days.integer' => '回款周期必须为整数',
|
|
'payment_cycle_days.min' => '回款周期不能小于 0',
|
|
'status.in' => '状态值不正确',
|
|
];
|
|
}
|
|
}
|