UploadRequest.php 915 Bytes
<?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'    => '请输入文件名称'
        ];
    }
}