From 6b320869d6b3e2d7e3c7b21053cf286a2d7efefa Mon Sep 17 00:00:00 2001 From: Bas van Dinther Date: Fri, 7 Feb 2025 10:09:15 +0100 Subject: [PATCH] fix: missing prefix (#23) * wip * Fix styling * Update README * Fix styling * Add missing . * Update README.md * Update README.md --------- Co-authored-by: Baspa <10845460+Baspa@users.noreply.github.com> Co-authored-by: Mark van Eijk --- README.md | 10 ++++++++++ src/FilamentMails.php | 27 ++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 694e183..c486da8 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,19 @@ 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(); + +// Prefix routes with path and/or name +FilamentMails::routes( + path: 'panel-path', + name: 'filament.panel' +); ``` +> [!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 73bcc54..eacec09 100644 --- a/src/FilamentMails.php +++ b/src/FilamentMails.php @@ -8,9 +8,30 @@ class FilamentMails { - public static function routes() + 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 { - Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview'); - Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download'); + static::$name = $name ?? 'filament.' . filament()->getDefaultPanel()->getId() . '.'; + } + + public static function routes(?string $path = null, ?string $name = null): void + { + static::setPath($path); + static::setName($name); + + 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'); + }); } }