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'); + }); } }