File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55use App \Events \StudentEnrolled ;
66use App \Notifications \EnrollmentConfirmation ;
77use Illuminate \Contracts \Queue \ShouldQueue ;
8+ use Illuminate \Support \Facades \Log ;
9+ use Throwable ;
810
911class SendEnrollmentConfirmationEmail implements ShouldQueue
1012{
@@ -22,8 +24,21 @@ class SendEnrollmentConfirmationEmail implements ShouldQueue
2224
2325 public function handle (StudentEnrolled $ event ): void
2426 {
25- $ event ->enrollment ->student ->notify (
26- new EnrollmentConfirmation ($ event ->enrollment )
27- );
27+ $ student = $ event ->enrollment ->student ;
28+
29+ // Guard: user may have been deleted between dispatch and processing
30+ if (! $ student ) {
31+ return ;
32+ }
33+
34+ $ student ->notify (new EnrollmentConfirmation ($ event ->enrollment ));
35+ }
36+
37+ public function failed (StudentEnrolled $ event , Throwable $ exception ): void
38+ {
39+ Log::error ('EnrollmentConfirmation notification failed after all retries ' , [
40+ 'enrollment_id ' => $ event ->enrollment ->id ,
41+ 'exception ' => $ exception ->getMessage (),
42+ ]);
2843 }
2944}
You can’t perform that action at this time.
0 commit comments