UserChangePwdRequest.php 1.03 KB
<?php

namespace App\Http\Request;

use App\Helpers\PasswordHelper;
use Hikoon\LaravelApi\Support\ApiRequest;

class UserChangePwdRequest extends ApiRequest
{
    /**
     * @return void
     */
    protected function passedValidation(): void
    {
        if ($this->has('password')) {
            $this->getInputSource()?->set('password', PasswordHelper::make($this->input('password')));
            optional($this->getValidatorInstance())->setData($this->all());
        }
    }


    /**
     * @inheritDoc
     */
    public function rules(): array
    {
        return [
            'password' => 'required|string|confirmed|min:6|max:20',
        ];
    }

    /**
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'password.required'  => '请输入新的密码',
            'password.min'       => '新的密码不能低于:min位',
            'password.max'       => '新的密码不能高于:max位',
            'password.confirmed' => '确认密码与新密码不一致'
        ];
    }
}