-
Add
$table->boolean('active')->default(false)
oncreate_users_table
migration. -
Create Model ActivationToken with Migration
php artisan make:model ActivationToken -m
-
Create columns on
create_activation_tokens_table
and referenceuser_id
tousers
table. -
Add relations on
User.php
andActivationToken.php
. Make sure to havestatic function
to lookupemail
forUser
andtoken
forActivationToken
. -
Bind RouteKey to look up
token
forActivationToken
Model and notid
public function getRouteKeyName()
{
return 'token';
}
- Create Events that handle Sending ActivationToken to Mail in
Providers\EventServiceProvider.php
.
protected $listen = [
'App\Events\Activation\RequestActivationToken' => [
'App\Listeners\Activation\SendActivationToken',
],
];
- then
php artisan event:generate
-
Add the code on
Events\Activation\RequestActivationToken
andListeners\Activation\SendActivationToken
respectively. -
Create Mail markdown to send
'token'
to user's email.
php artisan make:mail User\Activate\SendActivationMail --markdown="mail.user.activate.mail"
- Add the following components on
resources\views\mail\user\activate\mail.blade.php
template.
- Create ActivationTokenController under Auth (folder structure of your own choice)
php artisan make:controller Auth\Activation\ActivationTokenController
-
Add methods on
Auth\Activation\ActivationTokenController
to handle sending and receiving token to and from user's email. -
Add these routes on
routes\web.php
to handle sending and receiving request fromActivationTokenController
and mail template.
Route::group(['namespace' => 'Auth'], function () {
Route::get('activate/email/{token}', 'Activation\ActivationTokenController@activate')->name('activate.email');
Route::get('activate/resend', 'Activation\ActivationTokenController@resend')->name('resend.email');
});
-
These routes to be handled on
RegisterController.php
,LoginController.php
andResetPasswordController.php
through the events and listeners. -
Add code on
RegisterController.php
,LoginController.php
andResetPasswordController.php
that checks if user is active and sends activationToken ifactive => false
. -
If Successfully sending and receiving
token
to activate user then you are done. -
Advised to work with
mailtrap.io
while underAPP_ENV=local
then send to Gmail or your personal mail when testing after code completion.
Feel free to Contribute more If you working on such environments.
If you discover a security vulnerability within Laravel and such conditions, please send an e-mail to Laravel team taylor@laravel.com.
The Laravel framework is open-sourced software licensed under the MIT license.