ChatRecordRequest.php
3.6 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
+----------------------------------------------------------------------------------------------------------------------
* 数据验证层:ChatRecord 数据验证类
+----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Http\Requests
* @package App\Http\Requests
* @author Richer <yangzi1028@163.com>
* @date 2023年4月23日16:38:09
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Http\Requests;
/**
* Class ChatRecordRequest
* @package App\Http\Requests
*/
class ChatRecordRequest extends BaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes()
{
return [
'category_id' => '分类',
'labels' => '主题标签',
'body' => '提问内容',
];
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
// dd($this->type());
$data = ['body' => 'required|string|min:1|max:300'];
if ($this->request->get('type') == 2) {
$data['category_id'] = 'required|int|min:1';
// $data['labels'] = 'required|array';
// $data['labels.*.id'] = 'required|int|min:1';
// $data['labels.*.items'] = 'required|array';
// $data['labels.*.items.ids'] = 'required|array';
}
switch ($this->method()) {
// CREATE
case 'POST':
return $data;
// CREATE ROLES
return [
'category_id' => 'required|int|min:1',
'labels' => 'required|array',
'labels.*.id' => 'required|int|min:1',
'labels.*.items' => 'required|array',
'labels.*.items.ids' => 'required|array',
// 'labels.*.item.ids.*' => 'required|int|min:1',
// 'labels.items.0.supplement' => 'nullable|string',
'body' => 'required|string|min:1|max:300',
];
// UPDATE
case 'PUT':
case 'PATCH':
// UPDATE ROLES
return [];
case 'GET':
case 'DELETE':
default:
return [];
}
}
/**
* 提示信息
*
* @return array
*/
public function messages()
{
// 为了提示更准确,暂时不用框架自带的提示语句
$messages = [];
for ($i = 0;$i <= 10; $i++ ) {
$messages["labels.$i.items.required"] = "第" . str_number2chinese($i+1) ."个标签明细不能为空。";
$messages["labels.$i.items.array"] = "第" . str_number2chinese($i+1) ."个标签明细必须为数组。";
}
return $messages;
return [
// 'labels.0.items.required' => '请选择一个具体的标签',
// 'labels.item.*.ids.required' => '请选择一个具体的标签',
// 'labels.item.*.ids.array' => '请选择一个具体的标签',
// 'labels.item.0.supplement.string' => '补充标签必须是字符串',
];
}
}