diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 992754a..50262c9 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -13,7 +13,7 @@ jobs: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@2.3.0 + uses: aglipanci/laravel-pint-action@2.3.1 - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/README.md b/README.md index 2866139..a794bda 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,17 @@ You can install the package via composer: composer require concept7/filament-invite ``` +Register the plugin in your panel provider: +```php +use Concept7\FilamentInvite\InvitePlugin; + +public function panel(Panel $panel): Panel +{ + return $panel + ->plugin(new InvitePlugin()); +} +``` + You can publish and run the migrations with: ```bash @@ -38,6 +49,67 @@ php artisan vendor:publish --tag="filament-invite-views" use Concept7\FilamentInvite\Models\Traits\Invitable; ``` +### Create a mailable + +In app/Mail, create SendInviteMail.php, e.g. + +``` +user->email, + subject: 'You are invited to join ' . config('app.name'), + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + markdown: 'filament-invite::mail.invite', + with: [ + 'user' => $this->user, + 'link' => $this->url, + ] + ); + } +} +``` + ### Event listener If for some reason you need to listen to the InviteAccepted Event, you can register a listener handling a InviteProcessedEvent. Register the listener in your EventServiceProvider. diff --git a/composer.json b/composer.json index 5066b1d..e8411f6 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "filament/filament": "^3.0", "illuminate/contracts": "^10.0|^11.0", "illuminate/validation": "^10.0|^11.0", - "spatie/laravel-package-tools": "^1.13.5" + "spatie/laravel-package-tools": "^1.16" }, "require-dev": { "laravel/pint": "^1.0", diff --git a/config/filament-invite.php b/config/filament-invite.php index bdcdd33..e90496b 100644 --- a/config/filament-invite.php +++ b/config/filament-invite.php @@ -1,6 +1,7 @@ '24', + 'accept_route' => 'filament.admin.accept-invite', + 'after_login_redirect_route' => 'filament.admin.pages.dashboard', ]; diff --git a/routes/web.php b/routes/web.php index a7d5843..92e6262 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,13 +1,21 @@ middleware(config('filament.middleware.base')) - ->prefix(config('filament.path')) - ->name('filament.auth.') - ->group(function () { - Route::get('invite/accept/{acceptId}/{hash}', Accept::class) - // ->middleware('signed') - ->name('accept-invite'); - }); +Route::name('filament.')->group(function () { + foreach (Filament::getPanels() as $panel) { + $domains = $panel->getDomains(); + + foreach ((empty($domains) ? [null] : $domains) as $domain) { + Route::domain($domain) + ->middleware($panel->getMiddleware()) + ->name($panel->getId().'.') + ->prefix($panel->getPath()) + ->group(function () { + Route::get('invite/accept', Accept::class) + ->name('accept-invite'); + }); + } + } +}); diff --git a/src/FilamentInviteServiceProvider.php b/src/FilamentInviteServiceProvider.php index 2d826f0..5f791fe 100644 --- a/src/FilamentInviteServiceProvider.php +++ b/src/FilamentInviteServiceProvider.php @@ -3,9 +3,8 @@ namespace Concept7\FilamentInvite; use Concept7\FilamentInvite\Http\Livewire\Accept; -use Filament\Facades\Filament; -use Filament\Panel; use Livewire\Livewire; +use Spatie\LaravelPackageTools\Commands\InstallCommand; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -13,44 +12,10 @@ class FilamentInviteServiceProvider extends PackageServiceProvider { public static string $name = 'filament-invite'; - protected array $resources = [ - // CustomResource::class, - ]; - - protected array $pages = [ - // CustomPage::class, - ]; - - protected array $widgets = [ - // CustomWidget::class, - ]; - - protected array $styles = [ - // 'plugin-filament-invite' => __DIR__.'/../resources/dist/filament-invite.css', - ]; - - protected array $scripts = [ - // 'plugin-filament-invite' => __DIR__.'/../resources/dist/filament-invite.js', - ]; - - // protected array $beforeCoreScripts = [ - // 'plugin-filament-invite' => __DIR__ . '/../resources/dist/filament-invite.js', - // ]; - - public function register(): void - { - parent::register(); - - Filament::registerPanel( - $this->panel(Panel::make()), - ); - } - public function packageBooted(): void { + Livewire::component('concept7.'.static::$name.'.pages.accept', Accept::class); parent::packageBooted(); - - Livewire::component('accept', Accept::class); } public function configurePackage(Package $package): void @@ -59,18 +24,13 @@ public function configurePackage(Package $package): void ->name(static::$name) ->hasConfigFile() ->hasViews() - // ->hasRoute('web') + ->hasRoute('web') ->hasMigration('2023_05_19_083051_create_invites_table') - ->runsMigrations(); - } - - public function panel(Panel $panel): Panel - { - return $panel - ->id('invite') - ->path('invite') - ->pages([ - Accept::class, - ]); + ->runsMigrations() + ->hasInstallCommand(function (InstallCommand $command) { + $command + ->publishMigrations() + ->copyAndRegisterServiceProviderInApp(); + }); } } diff --git a/src/Http/Livewire/Accept.php b/src/Http/Livewire/Accept.php index 87ee2c6..2fd3907 100644 --- a/src/Http/Livewire/Accept.php +++ b/src/Http/Livewire/Accept.php @@ -126,7 +126,7 @@ public function submit() return route('filament.auth.login'); } - return redirect()->intended(route('filament.admin.pages.dashboard')); + return redirect()->intended(route(config('filament-invite.after_login_redirect_route'))); } diff --git a/src/InvitePlugin.php b/src/InvitePlugin.php new file mode 100644 index 0000000..0a02dbc --- /dev/null +++ b/src/InvitePlugin.php @@ -0,0 +1,34 @@ +getId()); + } +} diff --git a/src/Notifications/SendInviteNotification.php b/src/Notifications/SendInviteNotification.php index 4c3e5b9..8ef31f6 100644 --- a/src/Notifications/SendInviteNotification.php +++ b/src/Notifications/SendInviteNotification.php @@ -40,7 +40,7 @@ public function toMail(object $notifiable): SendInviteMail public function getLink(): string { - return route('filament.invite.pages.accept', [ + return route(config('filament-invite.accept_route'), [ 'acceptId' => $this->invite->id, 'hash' => $this->invite->token, ]);