First step is to overwrite the default methods in your User Model.
NB: We are still using the default Laravel Notifications.
# App/Models/User.php
<?php
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Auth\Notifications\ResetPassword;
class User extends Authenticatable implements MustVerifyEmail
{
...
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail());
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}
}
If you understand Queing, you can understand the rest from there. Finding those methods was the problem for me. If not, let's move on.
Create Custom Notification Classes that Extend the default Classes, and Queue the custom classes.
php artisan make:notification Auth/VerifyEmail
php artisan make:notification Auth/ResetPassword
# App\Notifications\Auth\VerifyEmail.php
<?php
namespace App\Notifications\Auth;
use Illuminate\Bus\Queueable;
use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
class VerifyEmail extends VerifyEmailNotification implements ShouldQueue
{
use Queueable;
public function __construct()
{
//specifying queue is optional but recommended
$this->queue = 'auth';
}
}
# App\Notifications\Auth\ResetPassword.php
<?php
namespace App\Notifications\Auth;
use Illuminate\Bus\Queueable;
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
class ResetPassword extends ResetPasswordNotification implements ShouldQueue
{
use Queueable;
public $token;
public function __construct($token)
{
//required to persist the token for the queue
$this->token = $token;
//specifying queue is optional but recommended
$this->queue = 'auth';
}
}
Now Update the methods in your User Model to use your custom classes
# App/Models/User.php
<?php
class User extends Authenticatable implements MustVerifyEmail
{
...
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new \App\Notifications\Auth\VerifyEmail());
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new \App\Notifications\Auth\ResetPassword($token));
}
}
Now, you may need to run a worker to check if everything’s playing out.
php artisan queue:work
NB: If you specified a queue name in your constructor
php artisan queue:work --queue=auth
You should Edit The passwords config and change the throttling message to a better one.
resources/lang/en/passwords.php
Example
'throttled' => 'You\'ve requested a password reset recently, please wait before retrying.',