diff --git a/src/Resources/MailResource.php b/src/Resources/MailResource.php index f8a3424..a22b615 100644 --- a/src/Resources/MailResource.php +++ b/src/Resources/MailResource.php @@ -29,8 +29,6 @@ class MailResource extends Resource { - protected static ?string $model = Mail::class; - protected static ?string $slug = 'mails'; protected static ?string $recordTitleAttribute = 'subject'; @@ -39,6 +37,11 @@ class MailResource extends Resource protected static bool $shouldRegisterNavigation = true; + public static function getModel(): string + { + return config('mails.models.mail'); + } + public static function getNavigationGroup(): ?string { return __('Mails'); diff --git a/src/Resources/MailResource/Pages/ListMails.php b/src/Resources/MailResource/Pages/ListMails.php index dbd0758..6143e2e 100644 --- a/src/Resources/MailResource/Pages/ListMails.php +++ b/src/Resources/MailResource/Pages/ListMails.php @@ -25,46 +25,48 @@ protected function getActions(): array public function getTabs(): array { + $class = config('mails.models.mail'); + return [ 'all' => Tab::make() ->label(__('All')) ->badgeColor('primary') ->icon('heroicon-o-inbox') - ->badge(Mail::count()), + ->badge($class::count()), 'sent' => Tab::make() ->label(__('Sent')) ->badgeColor('info') ->icon('heroicon-o-paper-airplane') - ->badge(Mail::sent()->count()) + ->badge($class::sent()->count()) ->modifyQueryUsing(fn (Builder $query) => $query->sent()), 'delivered' => Tab::make() ->label(__('Delivered')) ->badgeColor('success') ->icon('heroicon-o-check-circle') - ->badge(Mail::delivered()->count()) + ->badge($class::delivered()->count()) ->modifyQueryUsing(fn (Builder $query) => $query->delivered()), 'opened' => Tab::make() ->label(__('Opened')) ->badgeColor('info') ->icon('heroicon-o-eye') - ->badge(Mail::opened()->count()) + ->badge($class::opened()->count()) ->modifyQueryUsing(fn (Builder $query) => $query->opened()), 'clicked' => Tab::make() ->label(__('Clicked')) ->badgeColor('clicked') ->icon('heroicon-o-cursor-arrow-rays') - ->badge(Mail::clicked()->count()) + ->badge($class::clicked()->count()) ->modifyQueryUsing(fn (Builder $query) => $query->clicked()), 'bounced' => Tab::make() ->label(__('Bounced')) ->badgeColor('danger') ->icon('heroicon-o-x-circle') - ->badge(fn () => Mail::softBounced()->count() + Mail::hardBounced()->count()) + ->badge(fn () => $class::softBounced()->count() + $class::hardBounced()->count()) ->modifyQueryUsing(fn (Builder $query) => $query->where(function ($query) { $query->softBounced()->orWhere(function ($query) { $query->hardBounced(); @@ -75,7 +77,7 @@ public function getTabs(): array ->label(__('Unsent')) ->badgeColor('gray') ->icon('heroicon-o-x-circle') - ->badge(Mail::unsent()->count()) + ->badge($class::unsent()->count()) ->modifyQueryUsing(fn (Builder $query) => $query->unsent()), ]; } diff --git a/src/Resources/MailResource/Widgets/MailStatsWidget.php b/src/Resources/MailResource/Widgets/MailStatsWidget.php index 7064f95..b672e00 100644 --- a/src/Resources/MailResource/Widgets/MailStatsWidget.php +++ b/src/Resources/MailResource/Widgets/MailStatsWidget.php @@ -14,12 +14,14 @@ class MailStatsWidget extends BaseWidget protected function getStats(): array { - $bouncedMails = Mail::where(fn ($query) => $query->softBounced()->orWhere(fn ($query) => $query->hardBounced()))->count(); - $openedMails = Mail::opened()->count(); - $deliveredMails = Mail::delivered()->count(); - $clickedMails = Mail::clicked()->count(); - - $mailCount = Mail::count(); + $class = config('mails.models.mail'); + + $bouncedMails = $class::where(fn ($query) => $query->softBounced()->orWhere(fn ($query) => $query->hardBounced()))->count(); + $openedMails = $class::opened()->count(); + $deliveredMails = $class::delivered()->count(); + $clickedMails = $class::clicked()->count(); + + $mailCount = $class::count(); if ($mailCount === 0) { return [];