diff --git a/README.md b/README.md
index 851fbf7..e1ec03e 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,14 @@ Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-mails-views"
```
+Add the routes to your `web.php` file:
+
+```php
+use Vormkracht10\FilamentMails\Facades\FilamentMails;
+
+FilamentMails::routes();
+```
+
Then add the plugin to your `PanelProvider`
```php
@@ -73,6 +81,22 @@ public function panel(Panel $panel): Panel
}
```
+### Tenant middleware / route protection
+
+If you want to protect the mail routes with your (tenant) middleware, you can do so by adding the routes to the `tenantRoutes`:
+
+```php
+use Vormkracht10\FilamentMails\FilamentMailsPlugin;
+use Vormkracht10\FilamentMails\Facades\FilamentMails;
+
+public function panel(Panel $panel): Panel
+{
+ return $panel
+ ->plugin(FilamentMailsPlugin::make())
+ ->tenantRoutes(fn() => FilamentMails::routes());
+}
+```
+
> [!IMPORTANT]
> For setting up the webhooks to register mail events, please look into the README of [Laravel Mails](https://github.com/vormkracht10/laravel-mails), the underlying package that powers this package.
diff --git a/resources/views/mails/download.blade.php b/resources/views/mails/download.blade.php
index ff0d0a5..f94285c 100644
--- a/resources/views/mails/download.blade.php
+++ b/resources/views/mails/download.blade.php
@@ -1,2 +1,8 @@
-Download
diff --git a/resources/views/mails/preview.blade.php b/resources/views/mails/preview.blade.php
index aac81a4..0f45184 100644
--- a/resources/views/mails/preview.blade.php
+++ b/resources/views/mails/preview.blade.php
@@ -1,5 +1,6 @@
-
diff --git a/routes/web.php b/routes/web.php
deleted file mode 100644
index efe5467..0000000
--- a/routes/web.php
+++ /dev/null
@@ -1,8 +0,0 @@
-name('mail.preview');
-Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mail.attachment.download');
diff --git a/src/Controllers/MailDownloadController.php b/src/Controllers/MailDownloadController.php
index 05c1a32..7bc96cc 100644
--- a/src/Controllers/MailDownloadController.php
+++ b/src/Controllers/MailDownloadController.php
@@ -2,20 +2,25 @@
namespace Vormkracht10\FilamentMails\Controllers;
-use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Storage;
use Vormkracht10\Mails\Models\MailAttachment;
class MailDownloadController extends Controller
{
- public function __invoke(Request $request)
+ public function __invoke(string $tenant, string $mail, string $attachment, string $filename)
{
/** @var MailAttachment $attachment */
- $attachment = MailAttachment::find($request->attachment);
+ $attachment = MailAttachment::find($attachment);
- $file = Storage::disk($attachment->disk)->get($attachment->uuid);
+ $file = Storage::disk($attachment->disk)->path($attachment->uuid);
- return response()->download($file);
+ return response()->download(
+ file: $file,
+ name: $filename,
+ headers: [
+ 'Content-Type' => $attachment->mime,
+ ]
+ );
}
}
diff --git a/src/FilamentMails.php b/src/FilamentMails.php
index 62565f5..73bcc54 100644
--- a/src/FilamentMails.php
+++ b/src/FilamentMails.php
@@ -2,4 +2,15 @@
namespace Vormkracht10\FilamentMails;
-class FilamentMails {}
+use Illuminate\Support\Facades\Route;
+use Vormkracht10\FilamentMails\Controllers\MailDownloadController;
+use Vormkracht10\FilamentMails\Controllers\MailPreviewController;
+
+class FilamentMails
+{
+ public static function routes()
+ {
+ Route::get('mails/{mail}/preview', MailPreviewController::class)->name('mails.preview');
+ Route::get('mails/{mail}/attachment/{attachment}/{filename}', MailDownloadController::class)->name('mails.attachment.download');
+ }
+}
diff --git a/src/FilamentMailsServiceProvider.php b/src/FilamentMailsServiceProvider.php
index 9d584a3..a96236c 100644
--- a/src/FilamentMailsServiceProvider.php
+++ b/src/FilamentMailsServiceProvider.php
@@ -56,8 +56,6 @@ public function configurePackage(Package $package): void
if (file_exists($package->basePath('/../resources/views'))) {
$package->hasViews(static::$viewNamespace);
}
-
- $package->hasRoute('web');
}
public function packageRegistered(): void {}
@@ -113,8 +111,7 @@ protected function getAssets(): array
*/
protected function getCommands(): array
{
- return [
- ];
+ return [];
}
/**