From 4cebdae94e846dc9ba1127f50947af4dad96c1cf Mon Sep 17 00:00:00 2001 From: Baspa Date: Tue, 4 Feb 2025 08:33:11 +0100 Subject: [PATCH 1/7] wip --- src/FilamentMails.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/FilamentMails.php b/src/FilamentMails.php index 73bcc54..dcab293 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -8,9 +8,17 @@ class FilamentMails { - public static function routes() + public static function routes(?string $prefix = null) { - Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); - Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); + $routeGroup = function () { + Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); + Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); + }; + + if ($prefix) { + Route::prefix($prefix)->group($routeGroup); + } else { + $routeGroup(); + } } -} +} \ No newline at end of file From 6898ce378a7e4e581b5b07db2034df39fef60c9c Mon Sep 17 00:00:00 2001 From: Baspa <10845460+Baspa@users.noreply.github.com> Date: Tue, 4 Feb 2025 07:33:30 +0000 Subject: [PATCH 2/7] Fix styling --- src/FilamentMails.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FilamentMails.php b/src/FilamentMails.php index dcab293..2e3cd38 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -21,4 +21,4 @@ public static function routes(?string $prefix = null) $routeGroup(); } } -} \ No newline at end of file +} From 03dbb1afc804afc9754befa7c3fc83b7130b7f5f Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 7 Feb 2025 08:00:51 +0100 Subject: [PATCH 3/7] Update README --- README.md | 12 ++++++++++++ src/FilamentMails.php | 34 +++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 47065d2..81a3a18 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,21 @@ Add the routes to your `web.php` file: ```php use Vormkracht10\FilamentMails\Facades\FilamentMails; +// Basic usage - uses default Filament panel path and name +FilamentMails::routes(); + +// Custom path and name +FilamentMails::routes('custom-path', 'custom.name'); + +// Or set path and name separately +FilamentMails::setPath('custom-path'); +FilamentMails::setName('custom.name'); FilamentMails::routes(); ``` +> [!NOTE] +> By default, the path will be set to your Filament panel's path and the name will be 'filament.' followed by your panel's ID. You only need to customize these if you want different values. + Then add the plugin to your `PanelProvider` ```php diff --git a/src/FilamentMails.php b/src/FilamentMails.php index dcab293..97d84b9 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -8,17 +8,29 @@ class FilamentMails { - public static function routes(?string $prefix = null) + protected static string $path; + protected static string $name; + + public static function setPath(?string $path = null): void + { + static::$path = $path ?? filament()->getDefaultPanel()->getPath(); + } + + public static function setName(?string $name = null): void + { + static::$name = $name ?? 'filament.' . filament()->getDefaultPanel()->getId(); + } + + public static function routes(?string $path = null, ?string $name = null): void { - $routeGroup = function () { - Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); - Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); - }; + static::setPath($path); + static::setName($name); - if ($prefix) { - Route::prefix($prefix)->group($routeGroup); - } else { - $routeGroup(); - } + Route::prefix(static::$path) + ->name(static::$name) + ->group(function () { + Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); + Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); + }); } -} \ No newline at end of file +} From e2ac678fa632240f7437e6d152f852c03a29765b Mon Sep 17 00:00:00 2001 From: Baspa <10845460+Baspa@users.noreply.github.com> Date: Fri, 7 Feb 2025 07:01:31 +0000 Subject: [PATCH 4/7] Fix styling --- src/FilamentMails.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FilamentMails.php b/src/FilamentMails.php index 97d84b9..47eb66d 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -9,6 +9,7 @@ class FilamentMails { protected static string $path; + protected static string $name; public static function setPath(?string $path = null): void From bdb6b89a87f97b22d88546c0bd83ab40d33793e6 Mon Sep 17 00:00:00 2001 From: Baspa Date: Fri, 7 Feb 2025 08:13:53 +0100 Subject: [PATCH 5/7] Add missing . --- src/FilamentMails.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FilamentMails.php b/src/FilamentMails.php index 47eb66d..eacec09 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -19,7 +19,7 @@ public static function setPath(?string $path = null): void public static function setName(?string $name = null): void { - static::$name = $name ?? 'filament.' . filament()->getDefaultPanel()->getId(); + static::$name = $name ?? 'filament.' . filament()->getDefaultPanel()->getId() . '.'; } public static function routes(?string $path = null, ?string $name = null): void From 4db74052ee453da786764ce360e01ab78a76c7d8 Mon Sep 17 00:00:00 2001 From: Mark van Eijk Date: Fri, 7 Feb 2025 09:51:50 +0100 Subject: [PATCH 6/7] Update README.md --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 81a3a18..90f9bce 100644 --- a/README.md +++ b/README.md @@ -69,13 +69,11 @@ use Vormkracht10\FilamentMails\Facades\FilamentMails; // Basic usage - uses default Filament panel path and name FilamentMails::routes(); -// Custom path and name -FilamentMails::routes('custom-path', 'custom.name'); - -// Or set path and name separately -FilamentMails::setPath('custom-path'); -FilamentMails::setName('custom.name'); -FilamentMails::routes(); +// Prefix routes with path and/or name +FilamentMails::routes( + path: 'custom-path', + name: 'custom.name' +); ``` > [!NOTE] From 09ff83ef972db801d720a934a0ff6acd33418c55 Mon Sep 17 00:00:00 2001 From: Mark van Eijk Date: Fri, 7 Feb 2025 09:53:00 +0100 Subject: [PATCH 7/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 90f9bce..2d237c4 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ FilamentMails::routes(); // Prefix routes with path and/or name FilamentMails::routes( - path: 'custom-path', - name: 'custom.name' + path: 'panel-path', + name: 'filament.panel' ); ```