How can I simply validate an email in laravel, without creating a validator?
Validator::email($email)
does not work
By laravel ref
We can do like this Validator::make(['email' => $email], [ 'email' => 'email'])
OR
By using laravel helper we can do like this
validator(['email' => $email], ['email' => 'required|email']);
OR
Edit: We can further simplefy this by using macro
Add this in Service provider
$this
->app
->make(Validator::class)
->macro('email', function ($email) {
return Validator::make(['email' => $email], [ 'email' => 'email'])
});
And now we can use like this
Validator::email($email)
Note: Not test this just throwing some idea we can do this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With