diff --git a/src/Resources/SuppressionResource.php b/src/Resources/SuppressionResource.php index 53df0c6..e8855e4 100644 --- a/src/Resources/SuppressionResource.php +++ b/src/Resources/SuppressionResource.php @@ -66,32 +66,36 @@ public static function getNavigationIcon(): ?string public static function getEloquentQuery(): Builder { + $mailTable = config('mails.database.tables.mails'); + $eventTable = config('mails.database.tables.events'); + return parent::getEloquentQuery() - ->join('mails', 'mail_events.mail_id', '=', 'mails.id') + ->from("$eventTable as events") + ->join("$mailTable as mails", 'events.mail_id', '=', 'mails.id') ->where(function ($query) { - $query->where('type', EventType::HARD_BOUNCED) - ->orWhere('type', EventType::COMPLAINED); + $query->where('events.type', EventType::HARD_BOUNCED) + ->orWhere('events.type', EventType::COMPLAINED); }) - ->whereNull('unsuppressed_at') - ->whereIn('mails.to', function ($query) { + ->whereNull('events.unsuppressed_at') + ->whereIn('mails.to', function ($query) use ($eventTable) { $query->select('to') - ->from('mail_events') + ->from($eventTable) ->where('type', EventType::HARD_BOUNCED) ->whereNull('unsuppressed_at') ->groupBy('to'); }) - ->select('mail_events.*', 'mails.to') + ->select('events.*', 'mails.to') ->addSelect([ 'has_complained' => MailEvent::select('m.id') - ->from('mail_events AS me') - ->leftJoin('mails As m', function ($join) { + ->from("$eventTable as me") + ->leftJoin("$mailTable as m", function ($join) { $join->on('me.mail_id', '=', 'm.id') ->where('me.type', '=', EventType::COMPLAINED); }) ->take(1), ]) - ->latest('occurred_at') - ->orderBy('occurred_at', 'desc'); + ->latest('events.occurred_at') + ->orderBy('events.occurred_at', 'desc'); } public static function table(Table $table): Table @@ -101,14 +105,14 @@ public static function table(Table $table): Table ->columns([ Tables\Columns\TextColumn::make('to') ->label(__('Email address')) - ->formatStateUsing(fn ($record) => key(json_decode($record->to ?? []))) + ->formatStateUsing(fn($record) => key(json_decode($record->to ?? []))) ->searchable(['to']), Tables\Columns\TextColumn::make('id') ->label(__('Reason')) ->badge() - ->formatStateUsing(fn ($record) => $record->type->value == EventType::COMPLAINED->value ? 'Complained' : 'Bounced') - ->color(fn ($record): string => match ($record->type->value == EventType::COMPLAINED->value) { + ->formatStateUsing(fn($record) => $record->type->value == EventType::COMPLAINED->value ? 'Complained' : 'Bounced') + ->color(fn($record): string => match ($record->type->value == EventType::COMPLAINED->value) { true => 'danger', default => 'gray', }), @@ -117,7 +121,7 @@ public static function table(Table $table): Table ->label(__('Occurred At')) ->dateTime('d-m-Y H:i') ->since() - ->tooltip(fn (MailEvent $record) => $record->occurred_at->format('d-m-Y H:i')) + ->tooltip(fn(MailEvent $record) => $record->occurred_at->format('d-m-Y H:i')) ->sortable() ->searchable(), ]) @@ -127,7 +131,7 @@ public static function table(Table $table): Table ->action(function (MailEvent $record) { 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)); }) - ->visible(fn ($record) => Provider::tryFrom($record->mail->mailer == 'smtp' && filled($record->mail->transport) ? $record->mail->transport : $record->mail->mailer)), + ->visible(fn($record) => Provider::tryFrom($record->mail->mailer == 'smtp' && filled($record->mail->transport) ? $record->mail->transport : $record->mail->mailer)), Tables\Actions\ViewAction::make() ->url(null) @@ -136,7 +140,7 @@ public static function table(Table $table): Table ->label(__('View')) ->hiddenLabel() ->tooltip(__('View')) - ->infolist(fn (Infolist $infolist) => EventResource::infolist($infolist)), + ->infolist(fn(Infolist $infolist) => EventResource::infolist($infolist)), ]); }