Replies: 2 comments 5 replies
-
Hi. When I use custom messages, I write there all rules in words in one value, even if only one fails. |
Beta Was this translation helpful? Give feedback.
5 replies
-
@AbbasRam set the messages based on the required language on construct. Or create a form class for each language that you select via dependency injection with an interface. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Mainly I use FormRequests for validating requests because I think this is more clean. Also because All application I write needs to be in a language other then english so I should return error messages in a specific language. That's why I need FormRequest instead of
$request->validate()
function.I don't know which one is more popular (But I assume
$request->validate()
is more popular because nearly all of the questions on the internet regarding form validation turns around$request->validate()
function)But in the FormRequest version you should have two things. First you must have a rules() function which returns an array. All keys are form input field and all values are the validation rules that must be present for given input.
Secondly, you should have a messages() method.
Problem:
But there is an overhead here. One should repeat every combination of attribute / rule pairs in their messages array. So if its the case, I think it would be more useful if we were able to use just one
messages()
method because the messages array contains all the information to deduce the validation rules and their corresponding form input fields.Suggestion:
We may have a default version where we only use
rules()
method with default messages. Or we may use onlymessages()
method with custom messages and validation rules in the same place.Beta Was this translation helpful? Give feedback.
All reactions