@@ -66,32 +66,36 @@ public static function getNavigationIcon(): ?string
66
66
67
67
public static function getEloquentQuery (): Builder
68
68
{
69
+ $ mailTable = config ('mails.database.tables.mails ' );
70
+ $ eventTable = config ('mails.database.tables.events ' );
71
+
69
72
return parent ::getEloquentQuery ()
70
- ->join ('mails ' , 'mail_events.mail_id ' , '= ' , 'mails.id ' )
73
+ ->from ("$ eventTable as events " )
74
+ ->join ("$ mailTable as mails " , 'events.mail_id ' , '= ' , 'mails.id ' )
71
75
->where (function ($ query ) {
72
- $ query ->where ('type ' , EventType::HARD_BOUNCED )
73
- ->orWhere ('type ' , EventType::COMPLAINED );
76
+ $ query ->where ('events. type ' , EventType::HARD_BOUNCED )
77
+ ->orWhere ('events. type ' , EventType::COMPLAINED );
74
78
})
75
- ->whereNull ('unsuppressed_at ' )
76
- ->whereIn ('mails.to ' , function ($ query ) {
79
+ ->whereNull ('events. unsuppressed_at ' )
80
+ ->whereIn ('mails.to ' , function ($ query ) use ( $ eventTable ) {
77
81
$ query ->select ('to ' )
78
- ->from (' mail_events ' )
82
+ ->from ($ eventTable )
79
83
->where ('type ' , EventType::HARD_BOUNCED )
80
84
->whereNull ('unsuppressed_at ' )
81
85
->groupBy ('to ' );
82
86
})
83
- ->select ('mail_events .* ' , 'mails.to ' )
87
+ ->select ('events .* ' , 'mails.to ' )
84
88
->addSelect ([
85
89
'has_complained ' => MailEvent::select ('m.id ' )
86
- ->from (' mail_events AS me' )
87
- ->leftJoin (' mails As m ' , function ($ join ) {
90
+ ->from (" $ eventTable as me" )
91
+ ->leftJoin (" $ mailTable as m " , function ($ join ) {
88
92
$ join ->on ('me.mail_id ' , '= ' , 'm.id ' )
89
93
->where ('me.type ' , '= ' , EventType::COMPLAINED );
90
94
})
91
95
->take (1 ),
92
96
])
93
- ->latest ('occurred_at ' )
94
- ->orderBy ('occurred_at ' , 'desc ' );
97
+ ->latest ('events. occurred_at ' )
98
+ ->orderBy ('events. occurred_at ' , 'desc ' );
95
99
}
96
100
97
101
public static function table (Table $ table ): Table
@@ -101,14 +105,14 @@ public static function table(Table $table): Table
101
105
->columns ([
102
106
Tables \Columns \TextColumn::make ('to ' )
103
107
->label (__ ('Email address ' ))
104
- ->formatStateUsing (fn ($ record ) => key (json_decode ($ record ->to ?? [])))
108
+ ->formatStateUsing (fn ($ record ) => key (json_decode ($ record ->to ?? [])))
105
109
->searchable (['to ' ]),
106
110
107
111
Tables \Columns \TextColumn::make ('id ' )
108
112
->label (__ ('Reason ' ))
109
113
->badge ()
110
- ->formatStateUsing (fn ($ record ) => $ record ->type ->value == EventType::COMPLAINED ->value ? 'Complained ' : 'Bounced ' )
111
- ->color (fn ($ record ): string => match ($ record ->type ->value == EventType::COMPLAINED ->value ) {
114
+ ->formatStateUsing (fn ($ record ) => $ record ->type ->value == EventType::COMPLAINED ->value ? 'Complained ' : 'Bounced ' )
115
+ ->color (fn ($ record ): string => match ($ record ->type ->value == EventType::COMPLAINED ->value ) {
112
116
true => 'danger ' ,
113
117
default => 'gray ' ,
114
118
}),
@@ -117,7 +121,7 @@ public static function table(Table $table): Table
117
121
->label (__ ('Occurred At ' ))
118
122
->dateTime ('d-m-Y H:i ' )
119
123
->since ()
120
- ->tooltip (fn (MailEvent $ record ) => $ record ->occurred_at ->format ('d-m-Y H:i ' ))
124
+ ->tooltip (fn (MailEvent $ record ) => $ record ->occurred_at ->format ('d-m-Y H:i ' ))
121
125
->sortable ()
122
126
->searchable (),
123
127
])
@@ -127,7 +131,7 @@ public static function table(Table $table): Table
127
131
->action (function (MailEvent $ record ) {
128
132
event (new MailUnsuppressed (key ($ record ->mail ->to ), $ record ->mail ->mailer == 'smtp ' && filled ($ record ->mail ->transport ) ? $ record ->mail ->transport : $ record ->mail ->mailer , $ record ->mail ->stream_id ?? null ));
129
133
})
130
- ->visible (fn ($ record ) => Provider::tryFrom ($ record ->mail ->mailer == 'smtp ' && filled ($ record ->mail ->transport ) ? $ record ->mail ->transport : $ record ->mail ->mailer )),
134
+ ->visible (fn ($ record ) => Provider::tryFrom ($ record ->mail ->mailer == 'smtp ' && filled ($ record ->mail ->transport ) ? $ record ->mail ->transport : $ record ->mail ->mailer )),
131
135
132
136
Tables \Actions \ViewAction::make ()
133
137
->url (null )
@@ -136,7 +140,7 @@ public static function table(Table $table): Table
136
140
->label (__ ('View ' ))
137
141
->hiddenLabel ()
138
142
->tooltip (__ ('View ' ))
139
- ->infolist (fn (Infolist $ infolist ) => EventResource::infolist ($ infolist )),
143
+ ->infolist (fn (Infolist $ infolist ) => EventResource::infolist ($ infolist )),
140
144
]);
141
145
}
142
146
0 commit comments