ActivityUpdateRequest.php 3.4 KB
<?php

namespace App\Http\Container\UserSection\Requests;

use App\Http\Request\ActivityExpandRequest;
use App\Http\Service\ActivityService;

class ActivityUpdateRequest extends ActivityExpandRequest
{
    protected function prepareForValidation(): void
    {
        $this->merge(['is_lyric' => (int)ActivityService::isLyric($this->input('lyric'))]);
    }


    public function rules(): array
    {
        return [
            'cover'                      => 'required|url',
            'song_name'                  => 'required|string|between:0,100',
            'expand.tag_ids'             => 'array|between:0,3',
            'expand.tag_ids.*'           => 'numeric',
            'expand.lyricist.ids'        => 'array|max:2',
            'expand.lyricist.ids.*'      => 'numeric',
            'expand.composer.ids'        => 'array|max:2',
            'expand.composer.ids.*'      => 'numeric',
            'expand.guide_source.url'    => 'required|url',
            'expand.guide_source.name'   => 'required|string',
            'expand.guide_source.size'   => 'required|integer',
            'expand.karaoke_source.url'  => 'sometimes|url',
            'expand.karaoke_source.name' => 'sometimes|string',
            'expand.karaoke_source.size' => 'sometimes|integer',
            'lyric'                      => 'required',
            'is_lyric'                   => 'required|in:0,1',
        ];
    }

    public function messages(): array
    {
        return [
            'cover.required'                       => '请上传封面',
            'cover.url'                            => '无效的封面地址',
            'song_name.required'                   => '请输入歌曲名称',
            'song_name.between'                    => '歌曲名称长度应在:min~:max字节内',
            'project_id.required'                  => '请选择关联厂牌',
            'project_id.int'                       => '关联厂牌类型错误',
            'expand.lyricist.ids.array'            => '词作者(用户)类型错误',
            'expand.lyricist.ids.max'              => '词作者(用户)最多:max人',
            'expand.lyricist.ids.*.numeric'        => '词作者(用户)类型错误',
            'expand.lyricist.supplement.array'     => '词作者(未注册)类型错误',
            'expand.lyricist.supplement.max'       => '词作者(未注册)最多:max人',
            'expand.lyricist.supplement.*.numeric' => '词作者(未注册)类型错误',
            'expand.composer.ids.array'            => '曲作者(用户)类型错误',
            'expand.composer.ids.max'              => '曲作者(用户)最多:max人',
            'expand.composer.ids.*.numeric'        => '曲作者(用户)类型错误',
            'expand.composer.supplement.array'     => '曲作者(未注册)类型错误',
            'expand.composer.supplement.max'       => '曲作者(未注册)最多:max人',
            'expand.composer.supplement.*.numeric' => '曲作者(未注册)类型错误',

            'expand.guide_source.url.required' => '请上传导唱文件',
            'expand.guide_source.url.url'      => '无效的导唱文件链接',
            'expand.karaoke_source.url'        => '请上传伴奏文件',
            'expand.karaoke_source.url.url'    => '无效的伴奏文件链接',

            'lyric.required' => '请上传歌词文件',
            'lyric.regex'    => '歌词文件类型错误',
        ];
    }
}