<?php
namespace App\Http\Requests\Vendor;
use App\Traits\ResponseHandler;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class VendorPasswordRequest extends FormRequest
{
use ResponseHandler;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize():bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules():array
{
return [
'password' => 'required|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W)(?!.*\s).{8,}$/|same:confirm_password',
'confirm_password' => 'required',
];
}
public function messages(): array
{
return [
'password.required' => translate('The_password_field_is_required'),
'confirm_password.required' => translate('The_confirm_password_field_is_required'),
'password.same' => translate('The_password_and_confirm_password_must_be_match'),
'password.regex' => translate('The_password_must_be_at_least_8_characters_long_and_contain_at_least_one_uppercase_letter').','.translate('_one_lowercase_letter').','.translate('_one_digit_').','.translate('_one_special_character').','.translate('_and_no_spaces').'.',
];
}
protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
{
throw new HttpResponseException(response()->json(['errors' => $this->errorProcessor($validator)]));
}
}