Replies: 4 comments 4 replies
-
| Yes it is. If you use $this->validate() simplest one, then you should write code something like this:  | 
Beta Was this translation helpful? Give feedback.
-
|  | 
Beta Was this translation helpful? Give feedback.
-
| Not an answer, but something I tried that didn't cause any errors, but didn't actually work as hoped: Using the above, if any of the validations fail, the error contains all the error messages. So for example testing against an email address using a domain that I know isn't registered, and logging the result with: shows this in the log: Anyone got a workaround for this? | 
Beta Was this translation helpful? Give feedback.
-
| I did this with a workaround, i just created a custom rule that does the validations 1 by 1 <?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Validator;
class EmailRule implements ValidationRule
{
    /**
     * Run the validation rule.
     *
     * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
     */
    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        $validator = Validator::make([$attribute => $value], [
            $attribute => ['email:rfc'],
        ]);
        if ($validator->fails()) {
            $fail($validator->errors()->first());
        }
        $validator = Validator::make([$attribute => $value], [
            $attribute => ['email:dns'],
        ]);
        if ($validator->fails()) {
            $fail(__('custom message'));
        }
    }
} | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I use the below validation rule for validating emails. The default error message of "The :attribute must be a valid email address." is fine in most cases but I think it sometimes lacks information. For example for the end user it would be clearer to know that the domain is invalid if the dns rule fails.
'email:rfc,strict,dns,spoof'Is it possible to use a custom error message like below?
Beta Was this translation helpful? Give feedback.
All reactions