ConfigCreateRequest.php
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace App\Http\Container\AdminSection\Requests\System;
use App\Models\SystemConfig;
use Hikoon\LaravelApi\Support\ApiRequest;
use Illuminate\Support\Facades\Auth;
class ConfigCreateRequest extends ApiRequest
{
/**
* @return void
*/
protected function prepareForValidation(): void
{
$this->merge(['creator_id' => (int)Auth::id()]);
}
/**
* @return string[]
*/
public function rules(): array
{
return [
'parent_id' => 'required|numeric|int',
'identifier' => 'required|not_regex:/[\x7f-\xff]/|unique:' . SystemConfig::class . ',identifier,NULL,id,deleted_at,NULL',
'name' => 'required|string|between:0,100',
'expand.type' => 'required|string',
'content' => 'required_unless:expand.type,none|max:1000',
'remark' => 'nullable|max:400',
'status' => 'required|in:0,1',
'weight' => 'required|digits_between:0,200|integer',
'creator_id' => 'sometimes|integer'
];
}
/**
* @return string[]
*/
public function messages(): array
{
return [
'parent_id.required' => '请选择上级字典',
'parent_id.integer' => '请选择上级字典',
'identifier.required' => '请输入标识',
'identifier.not_regex' => '标识不能含有中文',
'identifier.unique' => '标识已存在',
'name.required' => '请输入名称',
'expand.type.required' => '请选择内容格式',
'content.required_unless' => '请输入内容',
'content.max' => '内容超出长度限制',
'remark.required' => '请输入备注',
'remark.max' => '备注超过长度限制',
'status.required' => '请选择状态',
'status.in' => '选择的状态值不在指定范围内',
'weight.required' => '请输入权重值',
'weight.integer' => '权重值应为整数值',
'weight.digits_between' => '权重值应在0~200之间'
];
}
}