ServerInformationRequest.php
2.2 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
<?php
namespace App\Http\Requests\Aside\Devops;
use App\Models\Devops\ServerInformation;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ServerInformationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'type' => [ 'required', Rule::in( array_keys( ( new ServerInformation )->ServiceArray() ) ) ],
'ip' => 'required|ip',
'title' => 'required|max:200',
'belong_to' => 'required|integer|in:1,2', // 1:公司 2:客户
'sshpass' => 'required|max:100',
'ports' => 'required|integer|min:1|max:65535',
];
}
public function messages()
{
$service_array = ( new ServerInformation )->ServiceArray();
$serviceStr = implode( ', ', $service_array );
return [
'type.required' => '服务器类型不能为空',
'type.integer' => '服务器类型格式不正确',
'type.between' => '服务器类型 ' . $serviceStr,
'ip.required' => 'ip不能为空',
'ip.ip' => 'ip格式不正确',
'title.required' => '服务器标题不能为空',
'title.max' => '服务器标题不能超过200个字符',
'belong_to.required' => '服务器归属不能为空',
'belong_to.integer' => '服务器归属格式不正确',
'belong_to.in' => '服务器归属只能是公司或者客户',
'sshpass.required' => 'ssh密码不能为空',
'sshpass.max' => 'ssh密码不能超过100个字符',
'ports.required' => 'ssh端口不能为空',
'ports.integer' => 'ssh端口格式不正确',
'ports.min' => 'ssh端口不能小于1',
'ports.max' => 'ssh端口不能大于65535',
];
}
}