User Email Verification For Laravel
jrean/laravel-user-verification is a Laravel package for user email verification for laravel.
It currently has 865 GitHub stars and 877.938 downloads on Packagist (latest version v14.0.0).
Install it with composer require jrean/laravel-user-verification.
Discover more Laravel packages by jrean
or browse all Laravel packages to compare alternatives.
Last updated
A PHP package built for Laravel to easily handle user verification and email validation.
| Laravel Version | Package Version | |-----------------|----------------------------------------------------------------------------------------------| | 5.0.* - 5.2.* | 2.2 | | 5.3.* | 3.0 | | 5.4.* | 4.1 | | 5.5.* | 5.0 | | 5.6.* | 6.0 | | 5.7.* - 5.8.* | 7.0 | | 6.0.* | 8.0 | | 7.0.* - 11.0.* | Use master or check below: | | 7.0.* | master | | 8.0.* | 9.0 | | 9.0.* | 10.0 | | 10.0.* | 11.0 | | 11.0.* | 12.0 | | 12.0.* | 13.0 | | 13.0.* | 14.0 |
This package is now Laravel 13.0 compliant with v14.0.0.
composer require jrean/laravel-user-verification
Add the service provider to config/app.php. Make sure to add it above the RouteServiceProvider.
'providers' => [
// ...
Jrean\UserVerification\UserVerificationServiceProvider::class,
// ...
App\Providers\RouteServiceProvider::class,
],
Optionally, add the facade:
'aliases' => [
// ...
'UserVerification' => Jrean\UserVerification\Facades\UserVerification::class,
],
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="config"
The package requires adding two columns to your users table: verified and verification_token.
php artisan migrate --path="/vendor/jrean/laravel-user-verification/src/resources/migrations"
Or publish and customize the migrations:
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="migrations"
Register the included middleware in app/Http/Kernel.php:
protected $routeMiddleware = [
// ...
'isVerified' => \Jrean\UserVerification\Middleware\IsVerified::class,
];
Apply it to routes:
Route::group(['middleware' => ['isVerified']], function () {
// Protected routes...
});
php artisan make:middleware IsVerified
The package includes a basic email template. The view receives a $user variable containing user details and the verification token.
Publish the views:
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="views"
The views will be available in resources/views/vendor/laravel-user-verification/.
To use Markdown instead of Blade templates, update the user-verification.php config:
'email' => [
'type' => 'markdown',
],
// Send immediately
UserVerification::send($user, 'Email Verification');
// Queue for sending
UserVerification::sendQueue($user, 'Email Verification');
// Send later
UserVerification::sendLater($seconds, $user, 'Email Verification');
The package provides two default routes:
Route::get('email-verification/error', 'Auth\RegisterController@getVerificationError')->name('email-verification.error');
Route::get('email-verification/check/{token}', 'Auth\RegisterController@getVerification')->name('email-verification.check');
Add the VerifiesUsers trait to your registration controller:
use Jrean\UserVerification\Traits\VerifiesUsers;
class RegisterController extends Controller
{
use RegistersUsers, VerifiesUsers;
// ...
}
Here's a typical implementation in RegisterController.php:
public function register(Request $request)
{
$this->validator($request->all())->validate();
$user = $this->create($request->all());
event(new Registered($user));
$this->guard()->login($user);
UserVerification::generate($user);
UserVerification::send($user, 'Please Verify Your Email');
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
Enable auto-login after verification in the config:
'auto-login' => true,
Publish translation files:
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="translations"
generate(AuthenticatableContract $user) - Generate and save a verification tokensend(AuthenticatableContract $user, $subject = null, $from = null, $name = null) - Send verification emailprocess($email, $token, $userTable) - Process the token verificationAdd the UserVerification trait to your User model for these methods:
isVerified() - Check if user is verifiedisPendingVerification() - Check if verification is pendingThe package throws the following exceptions:
ModelNotCompliantExceptionTokenMismatchExceptionUserIsVerifiedExceptionUserNotVerifiedExceptionUserNotFoundExceptionUserHasNoEmailExceptionLaravel User Verification is licensed under The MIT License (MIT).