From 8f121352b2d34de6d15ef709c0a507b83f636755 Mon Sep 17 00:00:00 2001 From: Mark van Eijk Date: Thu, 26 Mar 2026 21:35:43 +0100 Subject: [PATCH] fix: auto-register mail routes in plugin for both tenant and non-tenant panels Routes are now registered automatically when the plugin is installed, removing the need for manual route configuration in PanelProviders. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 30 +----------------------------- src/MailsPlugin.php | 4 +++- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index d20e794..bd850a0 100644 --- a/README.md +++ b/README.md @@ -62,19 +62,7 @@ Optionally, you can publish the views using php artisan vendor:publish --tag="mails-views" ``` -Add the routes to the PanelProvider using the `routes()` method, like this: - -```php -use Backstage\Mails\Facades\Mails; - -public function panel(Panel $panel): Panel -{ - return $panel - ->routes(fn () => Mails::routes()); -} -``` - -Then add the plugin to your `PanelProvider` +Add the plugin to your `PanelProvider` ```php use Backstage\Mails\MailsPlugin; @@ -118,22 +106,6 @@ $panel This example demonstrates how to combine role-based and permission-based access control, providing a more robust and flexible approach to managing access to mail resources. -### Tenant middleware and 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 Backstage\Mails\MailsPlugin; -use Backstage\Mails\Facades\Mails; - -public function panel(Panel $panel): Panel -{ - return $panel - ->plugin(MailsPlugin::make()) - ->tenantRoutes(fn() => Mails::routes()); -} -``` - > [!IMPORTANT] > For setting up the webhooks to register mail events, please look into the README of [Laravel Mails](https://github.com/backstagephp/laravel-mails), the underlying package that powers this package. diff --git a/src/MailsPlugin.php b/src/MailsPlugin.php index 037fc0d..c67b400 100644 --- a/src/MailsPlugin.php +++ b/src/MailsPlugin.php @@ -32,7 +32,9 @@ public function register(Panel $panel): void config('mails.resources.mail', MailResource::class), config('mails.resources.event', EventResource::class), config('mails.resources.suppression', SuppressionResource::class), - ]); + ]) + ->routes(fn () => Mails::routes()) + ->tenantRoutes(fn () => Mails::routes()); } public function boot(Panel $panel): void