diff --git a/README.md b/README.md index c7e0de1..05d8957 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,8 @@ return [ //Use this option for customize tenant model class //'tenant_model' => \App\Models\Team::class, + 'persist_team_id' => true, + ]; ``` diff --git a/config/filament-email.php b/config/filament-email.php index b9061b0..6a613a9 100644 --- a/config/filament-email.php +++ b/config/filament-email.php @@ -46,4 +46,6 @@ //Use this option for customize tenant model class //'tenant_model' => \App\Models\Team::class, + 'persist_team_id' => true, + ]; diff --git a/src/Listeners/FilamentEmailLogger.php b/src/Listeners/FilamentEmailLogger.php index ea31295..3c72bc8 100644 --- a/src/Listeners/FilamentEmailLogger.php +++ b/src/Listeners/FilamentEmailLogger.php @@ -31,7 +31,7 @@ public function handle(object $event): void $storeAttachments = config('filament-email.store_attachments', true); $model = config('filament-email.resource.model') ?? Email::class; - + $attachments = []; $savePath = 'filament-email-log'.DIRECTORY_SEPARATOR.date('YmdHis').'_'.Str::random(5).DIRECTORY_SEPARATOR; @@ -57,7 +57,7 @@ public function handle(object $event): void $savePathRaw = null; } $model::create([ - 'team_id' => Filament::getTenant()?->id ?? null, + 'team_id' => $this->getTeamId(), 'from' => $this->recipientsToString($email->getFrom()), 'to' => $this->recipientsToString($email->getTo()), 'cc' => $this->recipientsToString($email->getCc()), @@ -81,4 +81,13 @@ private function recipientsToString(array $recipients): string }, $recipients) ); } + + private function getTeamId(): ?int + { + if(config('filament-email.persist_team_id')){ + return Filament::getTenant()?->id ?? null; + } + + return null; + } }