jrean / laravel-user-verification
User Email Verification For Laravel
Installs: 788 883
Dependents: 8
Suggesters: 0
Security: 0
Stars: 856
Watchers: 20
Forks: 116
Open Issues: 7
Requires
- php: >=7.2.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.12|^3.5
- fzaninotto/faker: ^1.9|^1.5
- mockery/mockery: ^1.3
- phpunit/phpunit: ^7.0|^8.0|^9.0|^10.0|^11.0
- satooshi/php-coveralls: ^2.0|^1.0
- sllh/php-cs-fixer-styleci-bridge: ^2.1
- dev-master
- v13.0.0
- v12.0.0
- 11.0.x-dev
- v11.0.0
- v10.0.0
- v9.0.0
- 8.0.x-dev
- V8.0.0
- 7.0.x-dev
- v7.0.3
- v7.0.2
- v7.0.1
- v7.0.0
- 6.0.x-dev
- v6.0.2
- v6.0.1
- v6.0.0
- 5.0.x-dev
- v5.0.2
- v5.0.1
- v5.0.0
- 4.1.x-dev
- v4.1.11
- v4.1.10
- v4.1.9
- v4.1.8
- v4.1.7
- v4.1.6
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- 4.0.x-dev
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- 3.0.x-dev
- v3.0.25
- v3.0.24
- v3.0.23
- v3.0.22
- v3.0.21
- v3.0.20
- v3.0.19
- v3.0.18
- v3.0.17
- v3.0.16
- v3.0.15
- v3.0.14
- v3.0.13
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- 2.2.x-dev
- v2.2.29
- v2.2.28
- v2.2.27
- v2.2.26
- v2.2.25
- v2.2.24
- v2.2.23
- v2.2.22
- v2.2.21
- v2.2.20
- v2.2.19
- v2.2.18
- v2.2.17
- v2.2.16
- v2.2.15
- v2.2.14
- v2.2.13
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0
- v1.0
This package is auto-updated.
Last update: 2025-03-25 16:34:40 UTC
README
A PHP package built for Laravel to easily handle user verification and email validation.
Features
- Generate and store verification tokens for registered users
- Send or queue verification emails with token links
- Handle token verification process
- Set users as verified
- Relaunch the verification process anytime
Laravel Compatibility
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 |
This package is now Laravel 12.0 compliant with v13.0.0.
Installation
Via Composer
composer require jrean/laravel-user-verification
Register Service Provider & Facade
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, ],
Publish Configuration
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="config"
Database Configuration
The package requires adding two columns to your users table: verified
and verification_token
.
Run Migrations
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"
Middleware
Default Middleware
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... });
Custom Middleware
php artisan make:middleware IsVerified
Email Configuration
Default Email View
The package includes a basic email template. The view receives a $user
variable containing user details and the verification token.
Customize Email View
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/
.
Markdown Email Support
To use Markdown instead of Blade templates, update the user-verification.php
config:
'email' => [ 'type' => 'markdown', ],
Email Sending Methods
// Send immediately UserVerification::send($user, 'Email Verification'); // Queue for sending UserVerification::sendQueue($user, 'Email Verification'); // Send later UserVerification::sendLater($seconds, $user, 'Email Verification');
Usage
Routes
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');
Required Trait
Add the VerifiesUsers
trait to your registration controller:
use Jrean\UserVerification\Traits\VerifiesUsers; class RegisterController extends Controller { use RegistersUsers, VerifiesUsers; // ... }
Integration Example
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()); }
Auto-Login After Verification
Enable auto-login after verification in the config:
'auto-login' => true,
Translations
Publish translation files:
php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationServiceProvider" --tag="translations"
API Reference
Core Methods
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 verification
Model Traits
Add the UserVerification
trait to your User model for these methods:
isVerified()
- Check if user is verifiedisPendingVerification()
- Check if verification is pending
Error Handling
The package throws the following exceptions:
ModelNotCompliantException
TokenMismatchException
UserIsVerifiedException
UserNotVerifiedException
UserNotFoundException
UserHasNoEmailException
License
Laravel User Verification is licensed under The MIT License (MIT).