UserUpdateRequest.php 3.66 KB
<?php

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

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

class UserUpdateRequest extends ApiRequest
{
    /**
     * @return string[]
     */
    public function rules(): array
    {
        return [
            'nick_name'             => 'required|string|max:200',
            'real_name'             => 'required|string|max:200',
            'lang'                  => 'sometimes|string',
            'email'                 => 'required|email|unique:' . User::class . ',email,' . $this->route('user.id') . ',id,deleted_at,NULL',
            'area_code'             => 'required|string|max:6',
            'phone'                 => 'required|string|max:16|unique:' . User::class . ',phone,' . $this->route('user.id') . ',id,area_code,' . $this->input('area_code', 86) . ',deleted_at,NULL',
            'scope'                 => 'required|in:0,1,2',
            'business_singer_limit' => "sometimes|numeric|between:2,1000",
            'authIds'               => 'sometimes|array',
            'authIds.*'             => 'sometimes|numeric',
            'roleIds'               => 'required_if:scope,1|array',
            'roleIds.*'             => 'sometimes|numeric',
            'projectIds'            => 'required_if:scope,2|array',
            'projectIds.*'          => 'sometimes|numeric',
            'demo_type'             => 'required|in:0,1',
            'user_tag_id'           => 'required|numeric'
        ];
    }

    /**
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'nick_name.required'            => '请输入用户艺名',
            'nick_name.max'                 => '用户艺名长度不能超过:max',
            'real_name.required'            => '请输入用户真名',
            'real_name.max'                 => '用户真名长度不能超过:max',
            'email.required'                => '请输入用户邮箱',
            'email.email'                   => '用户邮箱格式不正确',
            'email.unique'                  => '邮箱已存在',
            'area_code.required'            => '请输入手机国际区号',
            'area_code.max'                 => '手机国际区号长度不能超过:max',
            'phone.required'                => '请输入手机号码',
            'phone.max'                     => '手机号码长度不能超过:max',
            'phone.unique'                  => '手机号码已存在',
            'scope.required'                => '请选择权限',
            'business_singer_limit.numeric' => '团队歌手数类型错误',
            'business_singer_limit.between' => '团队歌手数区间:min~:max',
            'scope.in'                      => '权限值不在指定范围内',
            'authIds.array'                 => '音乐认证格式不正确',
            'authIds.*.numeric'             => '音乐认证格式不正确',
            'roleIds.required_if'           => '请选择角色',
            'roleIds.array'                 => '角色格式不正确',
            'roleIds.*.numeric'             => '角色格式不正确',
            'projectIds.required_if'        => '请选择关联厂牌',
            'projectIds.array'              => '厂牌格式不正确',
            'projectIds.*.numeric'          => '厂牌格式不正确',
            'demo_type.required'            => '请选择个人Demo权限',
            'demo_type.in'                  => '个人Demo权限值不在指定范围内',
            'user_tag_id.required'          => '请选择标签',
            'user_tag_id.numeric'           => '标签类型错误'
        ];
    }
}