'Laravel Form Request custom error message for date_format rule
I want to add a custom message on date_format validation in laravel but conldn't find any thing.How i can add a custom message I have used this
$messages = [ 'postmeta.event_type.required' => 'event type is required', 'postmeta.event_type.date_format' => 'This is not working i want to add a custom message here', ];
$rules = [
'postmeta.start_date' => 'required|date_format:Y-m-d',
'postmeta.end_date' => 'required|date_format:Y-m-d',
'postmeta.start_time' => 'required|date_format:H:i:s',
'postmeta.end_time' => 'required|date_format:H:i:s',
];
But not getting the desire custom message. I am getting "The postmeta.end date does not match the format Y-m-d." but i want just event date.
Solution 1:[1]
In {project}\resources\lang
path, you can see different types of languages. for change validation message it just enough find the field intended in validation.php
and change the message.
you should change this:
'date_format' => 'The :attribute does not match the format :format.',
UPDATED:
in laravel V9 the lang folder is at the root of the project.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |