Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing prefix #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
}
}