VersionRequest.php 1.97 KB
<?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'       => '更新方式不在指定范围内'
        ];
    }
}