UploadRequest.php
915 Bytes
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
<?php
namespace App\Http\Container\AppSection\Requests;
use Closure;
use Hikoon\LaravelApi\Support\ApiRequest;
use Illuminate\Support\Str;
class UploadRequest extends ApiRequest
{
/**
* @return string[]
*/
public function rules(): array
{
return [
'contentType' => ['required', 'string', function (string $attribute, mixed $value, Closure $fail) {
$type = Str::before($value, '/');
if (!in_array($type, ['audio', 'image', 'video'])) {
$fail('上传文件类型尚未开放');
}
}],
'fileName' => 'required|string'
];
}
/**
* @return string[]
*/
public function messages(): array
{
return [
'contentType.required' => '上传文件类型',
'fileName.required' => '请输入文件名称'
];
}
}