I'm new to Laravel. I'm trying to create an API post request. This is the validation I have.
$request->validate([
'name' => 'required',
'phone' => 'required',
'address' => 'required',
'started_date' => 'required|after:2012-01-01|before:tomorrow',
]);
When the validation fails, with the validation I have, let's say "name" and "started_date" are missing, this is the response I get.
{
"message": "The given data was invalid.",
"errors": {
"name": [
"The name field is required."
],
"started_date": [
"The started date must be a date before tomorrow."
]
}
However, It's not the format I want. Here is what I want
{
"message": "The given data was invalid.",
"errors": {
"name": "The name field is required.",
"started_date": "The started date must be a date before tomorrow."
}
So what should I do to format the response?
"name": [ "The name field is required.","Some other error.","Another one", ], now you cannot simply do the desired transformation. Please explain why you want it to look diffrent?