philwgreen
4 years ago
383
11
Laravel

Form Validation: Custom Error Message With Input Value

Posted 4 years ago by philwgreen

I have a team registration form that collects four names (first and last), school and grade. Using the very handy unique_with validator I'm able to validate those entries to make sure they are unique in my database.

However, at the moment I'm struggling with how to display an error message that makes sense. Using a custom error message (This :attribute is already registered to a different team) it displays, "This firstName_1 is already registered to a different team." That is basically useless to the end user. Ideally it would say like, "John Smith has already been registered to another team." using the values that were entered into the form.

Is there a way to pull the input values into a custom error message?

Please sign in or create an account to participate in this conversation.