Laravel Installation
You can install the package via composer:
You can contribute to the package by visiting the GitHub repository (opens in a new tab).
composer require usevalid-email/laravel-sdk
Usage
Initialization
use UseValidEmail\LaravelSdk\LaravelSdk;
$token = env('USE_VALID_EMAIL_ACCESS_TOKEN'); // Use the access token from environment variables
$sdk = new LaravelSdk($token);
Validate Email
use Illuminate\Support\Facades\Validator;
$validator = Validator::make(['email' => 'test@example.com'], [
'email' => 'valid_email',
]);
if ($validator->fails()) {
echo "Invalid email.";
} else {
echo "Valid email.";
}
Controller Example
Here is an example of how to use the valid_email validator in a Laravel controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class EmailValidationController extends Controller
{
public function validateEmail(Request $request): \Illuminate\Http\RedirectResponse
{
$request->validate([
'email' => 'required|email|valid_email',
]);
return back()->with('success', 'Valid email.');
}
}