I have a Laravel API that returns JSON responses to the client. By default, Laravel sends error messages in a standard format, such as 422 Unprocessable Entity
. However, I want to send custom error messages to the client in a specific format, for example:
{
"status": "error",
"message": "Invalid email address"
}
I have tried using the abort function with a custom status code and message, but this does not send the response in the desired format. How can I send custom error messages to the client in the format shown above?