1616
1717namespace App \Notifications ;
1818
19+ use App \Http \Middleware \RateLimitOutboundMail ;
1920use App \Models \User ;
2021use App \Models \Warning ;
22+ use DateTime ;
2123use Illuminate \Bus \Queueable ;
24+ use Illuminate \Contracts \Queue \ShouldQueue ;
2225use Illuminate \Notifications \Messages \MailMessage ;
2326use Illuminate \Notifications \Notification ;
2427
25- class UserManualWarningExpire extends Notification
28+ class UserManualWarningExpire extends Notification implements ShouldQueue
2629{
2730 use Queueable;
2831
32+ /**
33+ * The maximum number of unhandled exceptions to allow before failing.
34+ */
35+ public int $ maxExceptions = 1 ;
36+
2937 /**
3038 * Create a new notification instance.
3139 */
@@ -43,6 +51,19 @@ public function via(object $notifiable): array
4351 return ['database ' , 'mail ' ];
4452 }
4553
54+ /**
55+ * Get the middleware the job should pass through.
56+ *
57+ * @return array<int, object>
58+ */
59+ public function middleware (object $ notifiable , string $ channel ): array
60+ {
61+ return match ($ channel ) {
62+ 'mail ' => [new RateLimitOutboundMail ()],
63+ default => [],
64+ };
65+ }
66+
4667 /**
4768 * Get the mail representation of the notification.
4869 */
@@ -70,4 +91,12 @@ public function toArray(object $notifiable): array
7091 'url ' => \sprintf ('/users/%s ' , $ this ->user ->username ),
7192 ];
7293 }
94+
95+ /**
96+ * Determine the time at which the job should timeout.
97+ */
98+ public function retryUntil (): DateTime
99+ {
100+ return now ()->addHours (2 );
101+ }
73102}
0 commit comments