From f575aa32d7aa4c33be77b6c0a3675c21f4efc5f5 Mon Sep 17 00:00:00 2001 From: Baran Berkay <48731845+bariskanberkay@users.noreply.github.com> Date: Mon, 26 May 2025 16:11:06 +0300 Subject: [PATCH 1/2] Update SuppressionResource.php Fix: Use configured mail and event table names instead of hardcoded values - Replaced hardcoded 'mails' and 'mail_events' table names with dynamic config-based values - Added table aliases ('events' and 'mails') for clarity and consistency - Ensured compatibility with custom table names defined in config/mails.php --- src/Resources/SuppressionResource.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Resources/SuppressionResource.php b/src/Resources/SuppressionResource.php index 53df0c6..4ec7979 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'); // 'for change mails package table name...' + $eventTable = config('mails.database.tables.events'); // 'for change mails package table name...' + return parent::getEloquentQuery() - ->join('mails', 'mail_events.mail_id', '=', 'mails.id') + ->from("$eventTable as events") // 💡 alias + ->join("$mailTable as mails", 'events.mail_id', '=', 'mails.id') // 💡 alias ->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 From 56f7e4267a1b58ab2029a75b9f6fcfef07bdc50a Mon Sep 17 00:00:00 2001 From: Baspa Date: Mon, 26 May 2025 19:22:17 +0200 Subject: [PATCH 2/2] Remove comments --- src/Resources/SuppressionResource.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Resources/SuppressionResource.php b/src/Resources/SuppressionResource.php index 4ec7979..e8855e4 100644 --- a/src/Resources/SuppressionResource.php +++ b/src/Resources/SuppressionResource.php @@ -66,12 +66,12 @@ public static function getNavigationIcon(): ?string public static function getEloquentQuery(): Builder { - $mailTable = config('mails.database.tables.mails'); // 'for change mails package table name...' - $eventTable = config('mails.database.tables.events'); // 'for change mails package table name...' + $mailTable = config('mails.database.tables.mails'); + $eventTable = config('mails.database.tables.events'); return parent::getEloquentQuery() - ->from("$eventTable as events") // 💡 alias - ->join("$mailTable as mails", 'events.mail_id', '=', 'mails.id') // 💡 alias + ->from("$eventTable as events") + ->join("$mailTable as mails", 'events.mail_id', '=', 'mails.id') ->where(function ($query) { $query->where('events.type', EventType::HARD_BOUNCED) ->orWhere('events.type', EventType::COMPLAINED); @@ -105,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', }), @@ -121,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(), ]) @@ -131,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) @@ -140,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)), ]); }