|
2 | 2 |
|
3 | 3 | namespace Moox\Expiry\Jobs; |
4 | 4 |
|
5 | | -use Carbon\Carbon; |
6 | 5 | use Illuminate\Bus\Queueable; |
7 | 6 | use Illuminate\Contracts\Queue\ShouldQueue; |
8 | 7 | use Illuminate\Foundation\Bus\Dispatchable; |
@@ -33,31 +32,32 @@ public function handle(): void |
33 | 32 | $query->whereNull('escalated_to') |
34 | 33 | ->whereNotNull('escalated_at'); |
35 | 34 | }) |
| 35 | + ->with('notifyUser') |
36 | 36 | ->get(); |
37 | 37 |
|
38 | 38 | if ($escalatedExpiries->isEmpty()) { |
39 | 39 | return; |
40 | 40 | } |
41 | 41 |
|
42 | | - $escalatedEntries = $escalatedExpiries->filter(fn ($entry): bool => isset($entry->escalated_at)); |
| 42 | + $escalatedEntries = $escalatedExpiries->filter(fn (Expiry $entry): bool => $entry->escalated_at !== null); |
43 | 43 |
|
44 | 44 | $data = [ |
45 | | - 'escalatedEntries' => $escalatedEntries->map(function (Expiry $entry) { |
| 45 | + 'escalatedEntries' => $escalatedEntries->map(function (Expiry $entry): array { |
46 | 46 | return [ |
47 | 47 | 'title' => $entry->title, |
48 | | - 'expired_at' => Carbon::parse($entry->expired_at)->diffForHumans(), |
49 | | - 'processing_deadline' => Carbon::parse($entry->processing_deadline)->diffForHumans(), |
50 | | - 'escalated_at' => Carbon::parse($entry->escalated_at)->format('d.m.Y'), |
51 | | - 'notified_to' => config('expiry.user_model')::where('ID', $entry->notified_to)->first()?->display_name, |
52 | | - 'user_email' => config('expiry.user_model')::where('ID', $entry->notified_to)->first()?->email, |
| 48 | + 'expired_at' => $entry->expired_at?->diffForHumans(), |
| 49 | + 'processing_deadline' => $entry->processing_deadline?->diffForHumans(), |
| 50 | + 'escalated_at' => $entry->escalated_at?->format('d.m.Y'), |
| 51 | + 'notified_to' => $entry->notifyUser?->display_name, |
| 52 | + 'user_email' => $entry->notifyUser?->email, |
53 | 53 | 'category' => $entry->category, |
54 | 54 | ]; |
55 | 55 | }), |
56 | 56 | ]; |
57 | 57 |
|
58 | | - $responsibleEmail = config('expiry.user_model')::where('ID', $escalatedExpiries->first()->notified_to)->first()?->email; |
| 58 | + $responsibleEmail = $escalatedExpiries->first()->notifyUser?->email; |
59 | 59 |
|
60 | | - Mail::to($responsibleEmail) |
| 60 | + Mail::to($responsibleEmail ?: $adminEmail) |
61 | 61 | ->cc($adminEmail) |
62 | 62 | ->send(new EscalatedExpiriesMail($data, $panelPath)); |
63 | 63 |
|
|
0 commit comments