SmsRequest.php 1.1 KB
<?php

namespace App\Http\Container\ProviderSection\Requests;

use App\Helpers\SmsHelper;
use App\Http\Request\PhoneCodeRequest;

class SmsRequest extends PhoneCodeRequest
{
    /**
     * @return void
     * @throws \Exception
     */
    public function passedValidation(): void
    {
        parent::passedValidation();
        $this->setCode(SmsHelper::createNumberCode(), $this->input('type'), $this->input('platform'));
    }


    /**
     * @return string[]
     */
    public function rules(): array
    {
        return array_merge($this->withoutRules('code'), [
            'platform' => 'required|in:app,admin,manage,user',
            'type'     => 'required|in:login,register,changePhone',
        ]);
    }

    /**
     * @return string[]
     */
    public function messages(): array
    {
        return array_merge($this->withoutMessage('code'), [
            'platform.required' => '请选择平台',
            'platform.in'       => '平台不在指定范围内',
            'type.required'     => '请选择申请场景',
            'type.in'           => '场景暂未开放',
        ]);
    }
}