BrokerPushConfigRequest.php 2.07 KB
<?php

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

use App\Models\BrokerPushConfig;
use Hikoon\LaravelApi\Support\ApiRequest;

class BrokerPushConfigRequest extends ApiRequest
{
    /**
     * @return void
     */
    protected function prepareForValidation(): void
    {
        $this->mergeIfMissing(['level_title' => '', 'match_title' => '']);

        if (empty($this->input('level_title'))) {
            $this->merge(['level_intro' => '']);
        }

        if (empty($this->input('match_title'))) {
            $this->merge(['match_intro' => '']);
        }
    }

    /**
     * @return string[]
     */
    public function rules(): array
    {
        return [
            'identifier'  => 'required|alpha:ascii|uppercase|max:32|unique:' . BrokerPushConfig::class . ',identifier,' . $this->route('push_config.id') . ',id,deleted_at,NULL',
            'level_title' => 'sometimes|string|max:64',
            'level_intro' => 'required_with:level_title|max:1000',
            'match_title' => 'sometimes|string|max:64',
            'match_intro' => 'required_with:match_title|max:1000'
        ];
    }

    /**
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'identifier.required'       => '请输入分类',
            'identifier.alpha'          => '分类仅支持A-Z字母组合',
            'identifier.uppercase'      => '分类仅支持A-Z字母组合',
            'identifier.max'            => '分类长度超过最大长度:max',
            'identifier.unique'         => '分类已存在,无法添加',
            'level_title.max'           => '等级通知标题超出最大长度:max',
            'level_intro.required_with' => '请输入等级通知内容',
            'level_intro .max'          => '等级通知内容超出最大长度:max',
            'match_title.max'           => '合作通知内容超出最大长度:max',
            'match_intro.required_with' => '请输入合作通知内容',
            'match_intro.max'           => '合作通知内容超出最大长度:max',
        ];
    }
}