MaterialRequest.php 1.29 KB
<?php

namespace App\Http\Container\AdminSection\Requests\System;

use Hikoon\LaravelApi\Support\ApiRequest;

class MaterialRequest extends ApiRequest
{
    public function rules(): array
    {
        return match ($this->method()) {
            'POST' => [
                'data.*.type'          => 'required',
                'data.*.url'           => 'required',
                'data.*.expand'        => 'required',
                'data.*.expand.width'  => 'required|integer',
                'data.*.expand.height' => 'required|integer'
            ],
            'PUT' => [
                'type'   => 'required',
                'url'    => 'required|url',
                'weight' => 'required|integer',
                'expand' => 'required'
            ],
            default => []
        };
    }

    public function messages(): array
    {
        return match ($this->method()) {
            'POST' => [
                '*.required'     => '请选择上传素材',
                'data.*.url.url' => '素材链接不正确',
            ],
            'PUT' => [
                '*.required'     => '请选择上传素材',
                'url.url'        => '素材链接不正确',
                'weight.integer' => '权重值异常'
            ],
            default => []
        };
    }
}