tjbp / laravel-verify-emails
Verify email addresses in Laravel <5.7 using the same pattern as password resets.
Installs: 1 356
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 4
Open Issues: 0
Requires
- illuminate/contracts: ^5.0
- illuminate/database: ^5.0
- illuminate/mail: ^5.0
- illuminate/support: ^5.0
Requires (Dev)
- mockery/mockery: ^0.9
- phpunit/phpunit: ^4.8
README
This package allows you to verify account emails in Laravel using the same pattern as password resets.
DEPRECATED: Email verification was implemented in the Laravel Framework for the release of 5.7 - if you're using 5.7 or above this package is unnecessary and if you're using a release below 5.6 it's no longer officially supported and you shouldn't be. This package will no longer be maintained.
Installation
This package is installable with Composer via Packagist.
Configuration
Add the following to config/auth.php
:
'verify_emails' => [ 'users' => [ 'provider' => 'users', 'email' => 'auth.emails.verify', 'table' => 'email_tokens', 'expire' => 60, ], ],
Change the passwords.users.table
setting to email_tokens
too, allowing password reset and email verification tokens to use the same table. Alternatively, create a new table for the email verification tokens using the same definitions as your password resets table and configure the above accordingly.
Usage
Implement the LaravelVerifyEmails\Contracts\Auth\CanVerifyEmail
contract in your App\User
model and use the LaravelVerifyEmails\Auth\VerifyEmails\CanVerifyEmail
trait to include the necessary methods. By default, a boolean column on your users table named verified
is expected. This behaviour can be altered by overriding the methods in the trait.
Add the LaravelVerifyEmails\Auth\VerifyEmails\VerifyEmailServiceProvider::class
service provider to the providers
array in config/app.php
.
Run php artisan make:verify-emails
to generate views, routes and a controller. Alternatively, use the LaravelVerifyEmails\Foundation\Auth\VerifiesEmails
trait in a controller of your choice.
Finally, call $user->unverify()
to mark the user as unverified and send a verification token to their email address. To catch unverified users, replace the auth
route middleware in App\Http\Kernel
with \LaravelVerifyEmails\Auth\Middleware\AuthenticateAndVerifyEmail::class
. If you'd rather use your own middleware, or want to check if a user is verified elsewhere, call $user->isVerified()
.
Licence
Laravel Verify Email is open-sourced software licensed under the MIT license.