Queueable Account Notifications

The email verification and password reset notifications are now handled on a queue.
This commit is contained in:
Refringe 2024-07-06 19:14:51 -04:00
parent 33ad76849e
commit 53b67b23dd
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
3 changed files with 63 additions and 0 deletions

View File

@ -2,6 +2,8 @@
namespace App\Models;
use App\Notifications\ResetPassword;
use App\Notifications\VerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -76,6 +78,22 @@ class User extends Authenticatable implements MustVerifyEmail
return Str::lower($this->role?->name) === 'administrator';
}
/**
* Overwritten to instead use the queued version of the VerifyEmail notification.
*/
public function sendEmailVerificationNotification(): void
{
$this->notify(new VerifyEmail);
}
/**
* Overwritten to instead use the queued version of the ResetPassword notification.
*/
public function sendPasswordResetNotification(#[\SensitiveParameter] $token): void
{
$this->notify(new ResetPassword($token));
}
protected function casts(): array
{
return [

View File

@ -0,0 +1,25 @@
<?php
namespace App\Notifications;
use Illuminate\Auth\Notifications\ResetPassword as OriginalResetPassword;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
/**
* This class exists solely to make the original notification queueable.
*/
class ResetPassword extends OriginalResetPassword implements ShouldQueue
{
use Queueable;
public function __construct($token)
{
parent::__construct($token);
}
public function toArray(object $notifiable): array
{
return [];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Notifications;
use Illuminate\Auth\Notifications\VerifyEmail as OriginalVerifyEmail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
/**
* This class exists solely to make the original notification queueable.
*/
class VerifyEmail extends OriginalVerifyEmail implements ShouldQueue
{
use Queueable;
public function toArray(object $notifiable): array
{
return [];
}
}