DynamicCreateRequest.php
1.79 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
<?php
namespace App\Http\Container\AppSection\Requests;
use Hikoon\LaravelApi\Support\ApiRequest;
class DynamicCreateRequest extends ApiRequest
{
protected function prepareForValidation(): void
{
$this->mergeIfMissing([
'intro' => ''
]);
}
/**
* @return string[]
*/
public function rules(): array
{
return [
'type' => 'required|in:image,audio,video',
'intro' => 'sometimes|nullable|string|max:400',
'properties' => 'required|array',
'properties.url' => 'required|string|url',
'properties.width' => 'sometimes|integer',
'properties.height' => 'sometimes|integer',
'properties.duration' => 'sometimes|numeric',
'properties.cover' => 'required_if:type,audio,video',
'properties.cover.url' => 'required_if:type,audio,video|string|url',
'properties.cover.width' => 'required_if:type,audio,video|integer',
'properties.cover.height' => 'required_if:type,audio,video|integer',
];
}
/**
* @return string[]
*/
public function messages(): array
{
return [
'type.required' => '请选择创建方式',
'type.in' => '创建方式暂未开放',
'intro.max' => '描述内容长度不能超过:max字节',
'properties.url.required' => '请选择上传文件',
'properties.url.url' => '上传文件链接不正确',
'properties.cover.required_if' => '请选择封面图片',
'properties.cover.url' => '封面图片链接不正确',
];
}
}