Skip to content

Commit

Permalink
fix: missing prefix (#23)
Browse files Browse the repository at this point in the history
* wip

* Fix styling

* Update README

* Fix styling

* Add missing .

* Update README.md

* Update README.md

---------

Co-authored-by: Baspa <[email protected]>
Co-authored-by: Mark van Eijk <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2025
1 parent 83d6f8f commit 6b32086
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions src/FilamentMails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
}

0 comments on commit 6b32086

Please sign in to comment.