adspace
How do I customize validation error messages for a form?
Answer Posted / Neeraj Semwal
To customize validation error messages in Laravel, you can use the `validate()` method with an instance of the `Validator` class. Here's an example:nn```phpnpublic function store(Request $request) {n $validatedData = $this->validate($request, [ // Your validation rules heren]);n}nn// app/Validation/Rules/CustomRule.phpnclass CustomRule extends Rule {n protected $message = 'This field is required and must be a valid number between 10 and 20.';nn public function passes($attribute, $value) {n return (is_numeric($value)) && ($value >= 10 && $value <= 20);n }n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers