Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Message #49

Open
shilpatipl opened this issue Oct 15, 2022 · 3 comments
Open

Custom Message #49

shilpatipl opened this issue Oct 15, 2022 · 3 comments

Comments

@shilpatipl
Copy link

I can't give custom messages.

public function rules() {
$rules = [
'card_number' => ['required', new CardNumber],
'expiry_year' => ['required', new CardExpirationYear($this->get('expiry_month'))],
'expiry_month' => ['required', new CardExpirationMonth($this->get('expiry_year'))],
'cvv' => ['required', new CardCvc($this->get('card_number'))]
];
}
return $rules;
}

public function messages() {
return [
'required' => 'The :attribute field is required',
'card_number.validation.credit_card.card_invalid' => 'Credit card is invalid',
'card_number.validation.credit_card.card_length_invalid' => 'Credit card is invalid'
];
}

public function failedValidation(Validator $validator) {
throw new HttpResponseException(response()->json($validator->errors(), 422));
}

@AlecDr
Copy link

AlecDr commented Oct 24, 2022

Hello @shilpatipl,

Have you tried defining an array like this

'credit_card' => [ 'card_invalid' => '', 'card_pattern_invalid' => '', 'card_length_invalid' => '', 'card_checksum_invalid' => '', 'card_expiration_year_invalid' => '', 'card_expiration_month_invalid' => '', 'card_expiration_date_invalid' => '', 'card_expiration_date_format_invalid' => '', 'card_cvc_invalid' => '' ]

at the botton of your lang/YOUR_LOCALE_HERE/validation.php file?

I didnt tested it but i believe this package uses the translation mechanism of laravel to define the message for each field.

@shilpatipl
Copy link
Author

Thanks @AlecDr It's working for me.

@slavcodev
Copy link

This seems not actual, please close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants