VersionRequest.php
1.97 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
<?php
namespace App\Http\Container\AdminSection\Requests\System;
use App\Models\AppVersion;
use Hikoon\LaravelApi\Support\ApiRequest;
class VersionRequest extends ApiRequest
{
public function rules(): array
{
return match ($this->method()) {
'POST' => [
'os' => 'bail|required|in:ios,android',
'app_ver' => ['bail', 'required', 'regex:/^\d+(?:\.\d+){2}$/'],
'app_no' => 'bail|required|numeric|unique:' . AppVersion::class . ',app_no,NULL,id,os,' . request()?->input('os') . ',deleted_at,NULL',
'url' => 'bail|required|url',
'is_force' => 'bail|required|in:0,1',
'remark' => 'bail|sometimes'
],
'PUT' => [
'os' => 'bail|required|in:ios,android',
'app_ver' => ['bail', 'required', 'regex:/^\d+(?:\.\d+){2}$/'],
'app_no' => 'bail|required|numeric|unique:' . AppVersion::class . ',app_no,' . $this->route('version')?->id . ',id,os,' . request()?->input('os') . ',deleted_at,NULL',
'url' => 'bail|required|url',
'is_force' => 'bail|required|in:0,1',
'remark' => 'bail|sometimes'
],
default => []
};
}
public function messages(): array
{
return [
'os.required' => '请选择系统类型',
'os.in' => '系统类型不在指定范围内',
'app_ver.required' => '请输入版本号',
'app_ver.regex' => "版本号格式不正确",
'app_no.required' => '请输入内部版本号',
'app_no.unique' => '内部号已存在',
'url.required' => "请上传版本文件",
'url.url' => "版本文件格式错误",
'is_force.required' => '请选择更新方式',
'is_force.in' => '更新方式不在指定范围内'
];
}
}