├── config ├── .gitkeep └── filament-saas-panel.php ├── resources ├── js │ └── .gitkeep ├── lang │ └── .gitkeep └── views │ ├── .gitkeep │ ├── livewire │ ├── sanctum-tokens.blade.php │ ├── contact-us.blade.php │ └── otp.blade.php │ ├── teams │ ├── api-tokens.blade.php │ └── edit-profile.blade.php │ ├── forms │ └── components │ │ ├── team-members.blade.php │ │ ├── delete-team-description.blade.php │ │ ├── delete-account-description.blade.php │ │ ├── team-owner.blade.php │ │ └── browser-sessions.blade.php │ └── emails │ └── team-invitation.blade.php ├── src ├── Console │ ├── .gitkeep │ └── FilamentSaasPanelInstall.php ├── Models │ ├── .gitkeep │ ├── Membership.php │ ├── TeamInvitation.php │ └── Team.php ├── Filament │ ├── Pages │ │ ├── .gitkeep │ │ ├── EditProfile │ │ │ ├── HasBrowserSessions.php │ │ │ ├── HasDeleteAccount.php │ │ │ ├── HasNotification.php │ │ │ ├── HasEditProfile.php │ │ │ └── HasEditPassword.php │ │ ├── EditTeam │ │ │ ├── HasDeleteTeam.php │ │ │ ├── HasNotifications.php │ │ │ ├── HasManageTeamMembers.php │ │ │ ├── HasCancelTeamInvitation.php │ │ │ ├── HasEditTeam.php │ │ │ ├── HasLeavingTeam.php │ │ │ ├── HasManageRoles.php │ │ │ └── HasTeamInvitation.php │ │ ├── ApiTokens.php │ │ ├── CreateTeam.php │ │ ├── EditTeam.php │ │ ├── Auth │ │ │ ├── LoginAccount.php │ │ │ ├── RegisterAccountWithoutOTP.php │ │ │ └── RegisterAccount.php │ │ └── EditProfile.php │ ├── Resources │ │ ├── .gitkeep │ │ ├── TeamResource │ │ │ ├── Filters │ │ │ │ └── TeamFilter.php │ │ │ ├── Pages │ │ │ │ └── ListTeams.php │ │ │ ├── Table │ │ │ │ └── TeamColumn.php │ │ │ ├── Form │ │ │ │ └── TeamComponent.php │ │ │ └── Actions │ │ │ │ ├── TeamTableAction.php │ │ │ │ └── TeamBulkAction.php │ │ └── TeamResource.php │ ├── Widgets │ │ └── .gitkeep │ └── Forms │ │ ├── EditProfileForm.php │ │ ├── UpdateTeamForm.php │ │ ├── EditPasswordForm.php │ │ ├── DeleteAccountForm.php │ │ ├── DeleteTeamForm.php │ │ ├── ManageTeamMembersForm.php │ │ └── BrowserSessionsForm.php ├── Http │ ├── Middleware │ │ └── .gitkeep │ ├── Requests │ │ └── .gitkeep │ └── Controllers │ │ ├── .gitkeep │ │ └── TeamsController.php ├── Responses │ └── RegisterResponse.php ├── Actions │ ├── Jetstream │ │ ├── DeleteTeam.php │ │ ├── UpdateTeamName.php │ │ ├── CreateTeam.php │ │ ├── DeleteUser.php │ │ ├── RemoveTeamMember.php │ │ ├── AddTeamMember.php │ │ └── InviteTeamMember.php │ └── Fortify │ │ ├── PasswordValidationRules.php │ │ ├── ResetUserPassword.php │ │ ├── UpdateUserPassword.php │ │ ├── CreateNewUser.php │ │ └── UpdateUserProfileInformation.php ├── Listeners │ ├── CreatePersonalTeam.php │ └── SwitchTeam.php ├── Events │ ├── SendOTP.php │ ├── SendWelcome.php │ ├── AccountLogged.php │ ├── AccountOTPCheck.php │ └── AccountRegistered.php ├── Mail │ └── TeamInvitation.php ├── Traits │ └── InteractsWithTenant.php ├── FilamentSaasTeamsPlugin.php └── FilamentSaasPanelServiceProvider.php ├── tests ├── src │ ├── Models │ │ ├── .gitkeep │ │ ├── Membership.php │ │ ├── TeamInvitation.php │ │ ├── User.php │ │ └── Team.php │ ├── DebugTest.php │ ├── TestAPIKeysPage.php │ ├── TestCreateTeamPage.php │ ├── TestRegisterPage.php │ ├── TestEditTeamPage.php │ ├── TestLoginPage.php │ ├── TestEditProfilePage.php │ ├── AdminPanelProvider.php │ ├── TestTeamsResource.php │ ├── AppPanelProvider.php │ ├── TestCase.php │ └── PluginTest.php ├── database │ ├── factories │ │ ├── .gitkeep │ │ ├── TeamFactory.php │ │ └── UserFactory.php │ ├── database.sqlite │ └── migrations │ │ ├── 2024_11_04_112951_create_teams_table.php │ │ ├── 2024_11_04_112952_create_team_invitations_table.php │ │ ├── 2024_07_15_150609_create_personal_access_tokens_table.php │ │ ├── 2024_11_04_112953_create_team_user_table.php │ │ ├── 2024_10_28_143941_add_media_if_not_exists_table.php │ │ └── 2025_08_25_143941_add_otp_fields_if_not_exists_table.php └── Pest.php ├── .github ├── FUNDING.yml ├── SECURITY.md ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── config.yaml │ └── bug.yml ├── workflows │ ├── fix-php-code-styling.yml │ ├── dependabot-auto-merge.yml │ └── tests.yml └── CONTRIBUTING.md ├── CHANGELOG.md ├── arts ├── login.png ├── otp.png ├── panel.png ├── api-tokens.png ├── edit-team.png ├── register.png ├── team-form.png ├── team-table.png ├── teams-list.png ├── create-team.png ├── create-token.png ├── delete-modal.png ├── edit-profile.png ├── logout-modal.png ├── team-invite.png ├── team-members.png ├── teams-action.png ├── token-modal.png ├── change-password.png ├── create-tenant.png ├── session-delete.png ├── team-settings.png ├── panel-tenant-menu.png ├── team-settings-not-owner.png └── fadymondy-tomato-saas-panel.jpg ├── SECURITY.md ├── publish ├── Membership.php ├── TeamInvitation.php ├── migrations │ ├── create_teams_table.php │ ├── create_team_invitations_table.php │ └── create_team_user_table.php ├── Team.php └── Account.php ├── .gitignore ├── fadymondy-tomato-saas-panel.md ├── routes └── web.php ├── LICENSE.md ├── phpunit.xml ├── database └── migrations │ ├── 2024_07_15_150609_create_personal_access_tokens_table.php │ ├── 2024_10_28_143941_add_media_if_not_exists_table copy.php │ └── 2025_08_25_143941_add_otp_fields_if_not_exists_table.php ├── testbench.yaml ├── module.json ├── composer.json └── CODE_OF_CONDUCT.md /config/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resources/js/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resources/lang/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Console/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resources/views/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Filament/Pages/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Http/Middleware/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Http/Requests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/src/Models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Filament/Resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Filament/Widgets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Http/Controllers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/database/factories/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [fadymondy] 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # V1.0.0 2 | 3 | First release of the package 4 | -------------------------------------------------------------------------------- /arts/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/login.png -------------------------------------------------------------------------------- /arts/otp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/otp.png -------------------------------------------------------------------------------- /arts/panel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/panel.png -------------------------------------------------------------------------------- /resources/views/livewire/sanctum-tokens.blade.php: -------------------------------------------------------------------------------- 1 |
2 | {{ $this->table }} 3 |
4 | -------------------------------------------------------------------------------- /arts/api-tokens.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/api-tokens.png -------------------------------------------------------------------------------- /arts/edit-team.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/edit-team.png -------------------------------------------------------------------------------- /arts/register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/register.png -------------------------------------------------------------------------------- /arts/team-form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/team-form.png -------------------------------------------------------------------------------- /arts/team-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/team-table.png -------------------------------------------------------------------------------- /arts/teams-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/teams-list.png -------------------------------------------------------------------------------- /arts/create-team.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/create-team.png -------------------------------------------------------------------------------- /arts/create-token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/create-token.png -------------------------------------------------------------------------------- /arts/delete-modal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/delete-modal.png -------------------------------------------------------------------------------- /arts/edit-profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/edit-profile.png -------------------------------------------------------------------------------- /arts/logout-modal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/logout-modal.png -------------------------------------------------------------------------------- /arts/team-invite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/team-invite.png -------------------------------------------------------------------------------- /arts/team-members.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/team-members.png -------------------------------------------------------------------------------- /arts/teams-action.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/teams-action.png -------------------------------------------------------------------------------- /arts/token-modal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/token-modal.png -------------------------------------------------------------------------------- /arts/change-password.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/change-password.png -------------------------------------------------------------------------------- /arts/create-tenant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/create-tenant.png -------------------------------------------------------------------------------- /arts/session-delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/session-delete.png -------------------------------------------------------------------------------- /arts/team-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/team-settings.png -------------------------------------------------------------------------------- /arts/panel-tenant-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/panel-tenant-menu.png -------------------------------------------------------------------------------- /tests/Pest.php: -------------------------------------------------------------------------------- 1 | in(__DIR__); 6 | -------------------------------------------------------------------------------- /tests/database/database.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/tests/database/database.sqlite -------------------------------------------------------------------------------- /arts/team-settings-not-owner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/team-settings-not-owner.png -------------------------------------------------------------------------------- /arts/fadymondy-tomato-saas-panel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomatophp/filament-saas-panel/HEAD/arts/fadymondy-tomato-saas-panel.jpg -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | If you discover any security related issues, please email info@3x1.io instead of using the issue tracker. 4 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | If you discover any security related issues, please email info@3x1.io instead of using the issue tracker. 4 | -------------------------------------------------------------------------------- /tests/src/DebugTest.php: -------------------------------------------------------------------------------- 1 | each->not->toBeUsed(); 5 | }); 6 | -------------------------------------------------------------------------------- /resources/views/teams/api-tokens.blade.php: -------------------------------------------------------------------------------- 1 | 2 | @livewire(\TomatoPHP\FilamentSaasPanel\Livewire\SanctumTokens::class) 3 | 4 | -------------------------------------------------------------------------------- /resources/views/forms/components/team-members.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{ trans('filament-saas-panel::messages.teams.members.team-members') }} 4 |
5 |
6 | -------------------------------------------------------------------------------- /publish/Membership.php: -------------------------------------------------------------------------------- 1 | to(route('otp')); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Models/Membership.php: -------------------------------------------------------------------------------- 1 | purge(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Listeners/CreatePersonalTeam.php: -------------------------------------------------------------------------------- 1 | schema(BrowserSessionsForm::get()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /resources/views/livewire/contact-us.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if(filament()->hasPlugin('filament-saas-accounts') && filament('filament-saas-accounts')->showContactUsButton) 3 |
4 | {{ trans('filament-accounts::messages.contact-us.footer') }} {{ $this->getContactUsAction }} 5 |
6 | 7 | 8 | @endif 9 |
10 | -------------------------------------------------------------------------------- /resources/views/forms/components/delete-team-description.blade.php: -------------------------------------------------------------------------------- 1 | 5 |
6 |
7 |
8 | {{ trans('filament-saas-panel::messages.profile.delete-team.body') }} 9 |
10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /resources/views/forms/components/delete-account-description.blade.php: -------------------------------------------------------------------------------- 1 | 5 |
6 |
7 |
8 | {{ trans('filament-saas-panel::messages.profile.delete.delete_account_card_description') }} 9 |
10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /fadymondy-tomato-saas-panel.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: SaaS Panel 3 | slug: fadymondy-tomato-saas-panel 4 | author_slug: fadymondy 5 | categories: [developer-tools] 6 | description: Ready to use SaaS panel with integration of Filament Accounts Builder and JetStream teams 7 | discord_url: 8 | docs_url: https://raw.githubusercontent.com/tomatophp/filament-saas-panel/master/README.md 9 | github_repository: tomatophp/filament-saas-panel 10 | has_dark_theme: true 11 | has_translations: true 12 | versions: [3,4] 13 | publish_date: 2024-11-04 14 | --- 15 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditProfile/HasDeleteAccount.php: -------------------------------------------------------------------------------- 1 | schema(DeleteAccountForm::get()) 14 | ->model($this->getUser()) 15 | ->statePath('deleteAccountData'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Filament/Resources/TeamResource/Filters/TeamFilter.php: -------------------------------------------------------------------------------- 1 | label(trans('filament-saas-panel::messages.filter')) 13 | ->searchable() 14 | ->preload() 15 | ->multiple() 16 | ->relationship('teams', 'name'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasDeleteTeam.php: -------------------------------------------------------------------------------- 1 | schema(DeleteTeamForm::get(Filament::getTenant())) 15 | ->model(Filament::getTenant()) 16 | ->statePath('deleteTeamData'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yaml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a question 4 | url: https://github.com/tomatophp/filament-saas-panel/discussions/new?category=q-a 5 | about: Ask the community for help 6 | - name: Request a feature 7 | url: https://github.com/tomatophp/filament-saas-panel/discussions/new?category=ideas 8 | about: Share ideas for new features 9 | - name: Report a security issue 10 | url: https://github.com/tomatophp/filament-saas-panel/security/policy 11 | about: Learn how to notify us for sensitive bugs 12 | -------------------------------------------------------------------------------- /src/Filament/Resources/TeamResource/Pages/ListTeams.php: -------------------------------------------------------------------------------- 1 | label(trans('filament-saas-panel::messages.column.teams')) 13 | ->circular() 14 | ->tooltip(fn ($record) => $record->teams()->pluck('name')->join(', ')) 15 | ->stacked(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Filament/Resources/TeamResource/Form/TeamComponent.php: -------------------------------------------------------------------------------- 1 | label(trans('filament-saas-panel::messages.column.teams')) 13 | ->columnSpanFull() 14 | ->multiple() 15 | ->searchable() 16 | ->preload() 17 | ->relationship('teams', 'name'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditProfile/HasNotification.php: -------------------------------------------------------------------------------- 1 | success() 13 | ->title(trans('filament-saas-panel::messages.saved_successfully')) 14 | ->send(); 15 | 16 | $data = $this->getUser()->attributesToArray(); 17 | 18 | $this->editProfileForm->fill($data); 19 | $this->editPasswordForm->fill(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/database/factories/TeamFactory.php: -------------------------------------------------------------------------------- 1 | create(); 16 | 17 | return [ 18 | 'name' => $this->faker->name(), 19 | 'personal_team' => false, 20 | 'user_id' => $user->id, 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Listeners/SwitchTeam.php: -------------------------------------------------------------------------------- 1 | getUser(); 25 | 26 | $team = $event->getTenant(); 27 | 28 | $user->switchTeam($team); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasNotifications.php: -------------------------------------------------------------------------------- 1 | success() 14 | ->title(trans('filament-saas-panel::messages.saved_successfully')) 15 | ->send(); 16 | 17 | $this->editTeamForm->fill(Filament::getTenant()->toArray()); 18 | $this->deleteTeamFrom->fill(Filament::getTenant()->toArray()); 19 | $this->manageTeamMembersForm->fill([]); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /publish/TeamInvitation.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | protected $fillable = [ 17 | 'email', 18 | 'role', 19 | ]; 20 | 21 | /** 22 | * Get the team that the invitation belongs to. 23 | */ 24 | public function team(): BelongsTo 25 | { 26 | return $this->belongsTo(Jetstream::teamModel()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/fix-php-code-styling.yml: -------------------------------------------------------------------------------- 1 | name: 'PHP Code Styling' 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - master 8 | paths: 9 | - '**.php' 10 | 11 | permissions: 12 | contents: write 13 | 14 | jobs: 15 | lint: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout code 19 | uses: actions/checkout@v5 20 | with: 21 | ref: ${{ github.head_ref }} 22 | 23 | - name: Fix PHP code style issues 24 | uses: aglipanci/laravel-pint-action@v2 25 | 26 | - name: Commit changes 27 | uses: stefanzweifel/git-auto-commit-action@v6 28 | with: 29 | commit_message: "Format Code" 30 | commit_user_name: 'GitHub Actions' 31 | -------------------------------------------------------------------------------- /src/Models/TeamInvitation.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | protected $fillable = [ 17 | 'email', 18 | 'role', 19 | ]; 20 | 21 | /** 22 | * Get the team that the invitation belongs to. 23 | */ 24 | public function team(): BelongsTo 25 | { 26 | return $this->belongsTo(Jetstream::teamModel()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/src/Models/TeamInvitation.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | protected $fillable = [ 17 | 'email', 18 | 'role', 19 | ]; 20 | 21 | /** 22 | * Get the team that the invitation belongs to. 23 | */ 24 | public function team(): BelongsTo 25 | { 26 | return $this->belongsTo(Jetstream::teamModel()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /resources/views/teams/edit-profile.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | {{ $this->editProfileForm }} 4 |
5 | 6 | @if(filament()->getPlugin('filament-saas-panel')->editPassword) 7 |
8 | {{ $this->editPasswordForm }} 9 |
10 | @endif 11 | 12 | @if(filament()->getPlugin('filament-saas-panel')->browserSessionManager) 13 |
14 | {{ $this->browserSessionsForm }} 15 |
16 | @endif 17 | 18 | @if(filament()->getPlugin('filament-saas-panel')->deleteAccount) 19 |
20 | {{ $this->deleteAccountForm }} 21 |
22 | @endif 23 |
24 | -------------------------------------------------------------------------------- /tests/database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | $this->faker->name(), 17 | 'email' => $this->faker->unique()->safeEmail(), 18 | 'email_verified_at' => now(), 19 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 20 | 'remember_token' => Str::random(10), 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | middleware('web', 'throttle:'.config('filament-saas-panel.throttle_otp')) 7 | ->name('otp'); 8 | 9 | Route::get('/users/team-invitations/{invitation}/accept', [\TomatoPHP\FilamentSaasPanel\Http\Controllers\TeamsController::class, 'accept']) 10 | ->middleware(['web', 'auth:'.config('filament-saas-panel.auth_guard')]) 11 | ->name('team-invitations.accept'); 12 | 13 | Route::get('/users/team-invitations/{invitation}/cancel', [\TomatoPHP\FilamentSaasPanel\Http\Controllers\TeamsController::class, 'cancel']) 14 | ->middleware(['web', 'auth:'.config('filament-saas-panel.auth_guard')]) 15 | ->name('team-invitations.cancel'); 16 | -------------------------------------------------------------------------------- /tests/src/TestAPIKeysPage.php: -------------------------------------------------------------------------------- 1 | create(); 8 | $team = $account->teams()->create([ 9 | 'user_id' => $account->id, 10 | 'name' => 'Team 1', 11 | 'personal_team' => true, 12 | ]); 13 | $account->current_team_id = $team->id; 14 | $account->save(); 15 | 16 | actingAs($account, config('filament-saas-panel.auth_guard')); 17 | }); 18 | 19 | it('can render api keys page', function () { 20 | get(\TomatoPHP\FilamentSaasPanel\Filament\Pages\ApiTokens::getUrl(['tenant' => auth(config('filament-saas-panel.auth_guard'))->user()->current_team_id]))->assertOk(); 21 | }); 22 | -------------------------------------------------------------------------------- /publish/migrations/create_teams_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('account_id')->references('id')->on('accounts')->onDelete('cascade'); 17 | $table->string('name'); 18 | $table->boolean('personal_team'); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | */ 26 | public function down(): void 27 | { 28 | Schema::dropIfExists('teams'); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasManageTeamMembers.php: -------------------------------------------------------------------------------- 1 | schema([ 15 | Section::make(trans('filament-saas-panel::messages.teams.members.title')) 16 | ->description(trans('filament-saas-panel::messages.teams.members.description')) 17 | ->schema(ManageTeamMembersForm::get(Filament::getTenant())), 18 | ]) 19 | ->model(Filament::getTenant()) 20 | ->statePath('manageTeamMembersData'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Events/SendOTP.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('user_id')->references('id')->on('users')->onDelete('cascade'); 17 | $table->string('name'); 18 | $table->boolean('personal_team'); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | */ 26 | public function down(): void 27 | { 28 | Schema::dropIfExists('teams'); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /src/Events/AccountLogged.php: -------------------------------------------------------------------------------- 1 | 2 | @livewire('notifications') 3 | 4 |
5 | 10 | 11 |
12 | {{ $this->form }} 13 | 14 |
17 | 21 |
22 |
23 |
24 | 25 | -------------------------------------------------------------------------------- /src/Actions/Fortify/ResetUserPassword.php: -------------------------------------------------------------------------------- 1 | $input 18 | */ 19 | public function reset(Account $user, array $input): void 20 | { 21 | Validator::make($input, [ 22 | 'password' => $this->passwordRules(), 23 | ])->validate(); 24 | 25 | $user->forceFill([ 26 | 'password' => Hash::make($input['password']), 27 | ])->save(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Events/AccountOTPCheck.php: -------------------------------------------------------------------------------- 1 | create(), config('filament-saas-panel.auth_guard')); 8 | }); 9 | 10 | it('can render create team page', function () { 11 | get(url(config('filament-saas-panel.id').'/new'))->assertOk(); 12 | }); 13 | 14 | it('can register new team', function () { 15 | 16 | \Pest\Livewire\livewire(\TomatoPHP\FilamentSaasPanel\Filament\Pages\CreateTeam::class) 17 | ->fillForm([ 18 | 'name' => 'Team 1', 19 | ]) 20 | ->call('register'); 21 | 22 | \Pest\Laravel\assertDatabaseHas(\TomatoPHP\FilamentSaasPanel\Models\Team::class, [ 23 | 'name' => 'Team 1', 24 | 'user_id' => auth(config('filament-saas-panel.auth_guard'))->user()->id, 25 | ]); 26 | }); 27 | -------------------------------------------------------------------------------- /publish/migrations/create_team_invitations_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('team_id')->constrained()->cascadeOnDelete(); 17 | $table->string('email'); 18 | $table->string('role')->nullable(); 19 | $table->timestamps(); 20 | 21 | $table->unique(['team_id', 'email']); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down(): void 29 | { 30 | Schema::dropIfExists('team_invitations'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /tests/database/migrations/2024_11_04_112952_create_team_invitations_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('team_id')->constrained()->cascadeOnDelete(); 17 | $table->string('email'); 18 | $table->string('role')->nullable(); 19 | $table->timestamps(); 20 | 21 | $table->unique(['team_id', 'email']); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down(): void 29 | { 30 | Schema::dropIfExists('team_invitations'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /src/Actions/Jetstream/UpdateTeamName.php: -------------------------------------------------------------------------------- 1 | $input 17 | */ 18 | public function update(Model $user, Model $team, array $input): void 19 | { 20 | Gate::forUser($user)->authorize('update', arguments: $team); 21 | 22 | Validator::make($input, [ 23 | 'name' => ['required', 'string', 'max:255'], 24 | ])->validateWithBag('updateTeamName'); 25 | 26 | $team->forceFill([ 27 | 'name' => $input['name'], 28 | ])->save(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Filament/Pages/ApiTokens.php: -------------------------------------------------------------------------------- 1 | owner->id); 3 | @endphp 4 | 5 |
6 | 9 | 10 |
11 |
12 | 18 |
19 |
20 |
21 | {{ $user->name }} 22 |
23 |
24 | {{ $user->email }} 25 |
26 |
27 |
28 |
29 | -------------------------------------------------------------------------------- /src/Actions/Jetstream/CreateTeam.php: -------------------------------------------------------------------------------- 1 | $input 16 | */ 17 | public function create(mixed $user, array $input): Model 18 | { 19 | Validator::make($input, [ 20 | 'name' => ['required', 'string', 'max:255'], 21 | ])->validateWithBag('createTeam'); 22 | 23 | AddingTeam::dispatch($user); 24 | 25 | $user->switchTeam($team = $user->ownedTeams()->create([ 26 | 'name' => $input['name'], 27 | 'personal_team' => false, 28 | ])); 29 | 30 | $user->current_team_id = $team->id; 31 | $user->teams()->attach([$team->id]); 32 | 33 | return $team; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /resources/views/emails/team-invitation.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::message') 2 | {{ __('You have been invited to join the :team team!', ['team' => $invitation->team->name]) }} 3 | 4 | @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::registration())) 5 | {{ __('If you do not have an account, you may create one by clicking the button below. After creating an account, you may click the invitation acceptance button in this email to accept the team invitation:') }} 6 | 7 | @component('mail::button', ['url' => filament()->getCurrentPanel()->getId() . '/' . config('filament-saas-panel.registration_url')]) 8 | {{ __('Create Account') }} 9 | @endcomponent 10 | 11 | {{ __('If you already have an account, you may accept this invitation by clicking the button below:') }} 12 | 13 | @else 14 | {{ __('You may accept this invitation by clicking the button below:') }} 15 | @endif 16 | 17 | 18 | @component('mail::button', ['url' => $acceptUrl]) 19 | {{ __('Accept Invitation') }} 20 | @endcomponent 21 | 22 | {{ __('If you did not expect to receive an invitation to this team, you may discard this email.') }} 23 | @endcomponent 24 | -------------------------------------------------------------------------------- /src/Console/FilamentSaasPanelInstall.php: -------------------------------------------------------------------------------- 1 | info('Publish Vendor Assets'); 39 | $this->artisanCommand(['migrate']); 40 | $this->artisanCommand(['optimize:clear']); 41 | $this->info('Filament SaaS Panel installed successfully.'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | ./src 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Actions/Fortify/UpdateUserPassword.php: -------------------------------------------------------------------------------- 1 | $input 18 | */ 19 | public function update(Account $user, array $input): void 20 | { 21 | Validator::make($input, [ 22 | 'current_password' => ['required', 'string', 'current_password:web'], 23 | 'password' => $this->passwordRules(), 24 | ], [ 25 | 'current_password.current_password' => __('The provided password does not match your current password.'), 26 | ])->validateWithBag('updatePassword'); 27 | 28 | $user->forceFill([ 29 | 'password' => Hash::make($input['password']), 30 | ])->save(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasCancelTeamInvitation.php: -------------------------------------------------------------------------------- 1 | requiresConfirmation() 14 | ->color('danger') 15 | ->label(trans('filament-saas-panel::messages.teams.actions.cancel_invitation')) 16 | ->action(function (array $arguments) { 17 | $this->cancelTeamInvitation($arguments['invitation']); 18 | }); 19 | } 20 | 21 | public function cancelTeamInvitation($invitationId) 22 | { 23 | try { 24 | if (! empty($invitationId)) { 25 | $model = config('filament-saas-panel.team_invitation_model'); 26 | 27 | $model::whereKey($invitationId)->delete(); 28 | } 29 | } catch (Halt $exception) { 30 | return; 31 | } 32 | 33 | $this->sendSuccessNotification(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2024_07_15_150609_create_personal_access_tokens_table.php: -------------------------------------------------------------------------------- 1 | id(); 17 | $table->morphs('tokenable'); 18 | $table->string('name'); 19 | $table->string('token', 64)->unique(); 20 | $table->text('abilities')->nullable(); 21 | $table->timestamp('last_used_at')->nullable(); 22 | $table->timestamp('expires_at')->nullable(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | */ 32 | public function down(): void 33 | { 34 | Schema::dropIfExists('personal_access_tokens'); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /tests/database/migrations/2024_07_15_150609_create_personal_access_tokens_table.php: -------------------------------------------------------------------------------- 1 | id(); 17 | $table->morphs('tokenable'); 18 | $table->string('name'); 19 | $table->string('token', 64)->unique(); 20 | $table->text('abilities')->nullable(); 21 | $table->timestamp('last_used_at')->nullable(); 22 | $table->timestamp('expires_at')->nullable(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | */ 32 | public function down(): void 33 | { 34 | Schema::dropIfExists('personal_access_tokens'); 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /.github/workflows/dependabot-auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: dependabot-auto-merge 2 | on: pull_request_target 3 | 4 | permissions: 5 | pull-requests: write 6 | contents: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: ${{ github.actor == 'dependabot[bot]' }} 12 | steps: 13 | 14 | - name: Dependabot metadata 15 | id: metadata 16 | uses: dependabot/fetch-metadata@v2.4.0 17 | with: 18 | github-token: "${{ secrets.GITHUB_TOKEN }}" 19 | 20 | - name: Auto-merge Dependabot PRs for semver-minor updates 21 | if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} 22 | run: gh pr merge --auto --merge "$PR_URL" 23 | env: 24 | PR_URL: ${{github.event.pull_request.html_url}} 25 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 26 | 27 | - name: Auto-merge Dependabot PRs for semver-patch updates 28 | if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} 29 | run: gh pr merge --auto --merge "$PR_URL" 30 | env: 31 | PR_URL: ${{github.event.pull_request.html_url}} 32 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 33 | -------------------------------------------------------------------------------- /tests/database/migrations/2024_11_04_112953_create_team_user_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('team_id'); 17 | $table->foreignId('user_id')->references('id')->on('users')->onDelete('cascade'); 18 | $table->string('role')->nullable(); 19 | $table->timestamps(); 20 | 21 | $table->unique(['team_id', 'account_id']); 22 | }); 23 | 24 | Schema::table('users', function (Blueprint $table) { 25 | $table->foreignId('current_team_id')->nullable(); 26 | $table->string('profile_photo_path', 2048)->nullable(); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | */ 33 | public function down(): void 34 | { 35 | Schema::dropIfExists('team_user'); 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /src/Mail/TeamInvitation.php: -------------------------------------------------------------------------------- 1 | invitation = $invitation; 30 | } 31 | 32 | /** 33 | * Build the message. 34 | * 35 | * @return $this 36 | */ 37 | public function build() 38 | { 39 | return $this->markdown(config('filament-saas-panel.team_invitation_mail_view'), ['acceptUrl' => URL::signedRoute('team-invitations.accept', [ 40 | 'invitation' => $this->invitation, 41 | ])])->subject(__('Team Invitation')); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /publish/migrations/create_team_user_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('team_id'); 17 | $table->foreignId('account_id')->references('id')->on('accounts')->onDelete('cascade'); 18 | $table->string('role')->nullable(); 19 | $table->timestamps(); 20 | 21 | $table->unique(['team_id', 'account_id']); 22 | }); 23 | 24 | Schema::table('accounts', function (Blueprint $table) { 25 | $table->rememberToken(); 26 | $table->foreignId('current_team_id')->nullable(); 27 | $table->string('profile_photo_path', 2048)->nullable(); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | */ 34 | public function down(): void 35 | { 36 | Schema::dropIfExists('team_user'); 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /testbench.yaml: -------------------------------------------------------------------------------- 1 | providers: 2 | - BladeUI\Icons\BladeIconsServiceProvider 3 | - BladeUI\Heroicons\BladeHeroiconsServiceProvider 4 | - Filament\Actions\ActionsServiceProvider 5 | - Filament\FilamentServiceProvider 6 | - Filament\Forms\FormsServiceProvider 7 | - Filament\Infolists\InfolistsServiceProvider 8 | - Filament\Notifications\NotificationsServiceProvider 9 | - Filament\Support\SupportServiceProvider 10 | - Laravel\Jetstream\JetstreamServiceProvider 11 | - Laravel\Fortify\FortifyServiceProvider 12 | - Spatie\MediaLibrary\MediaLibraryServiceProvider 13 | - Livewire\LivewireServiceProvider 14 | - Filament\Schemas\SchemasServiceProvider 15 | - Filament\Tables\TablesServiceProvider 16 | - Filament\Widgets\WidgetsServiceProvider 17 | - Filament\Schemas\SchemasServiceProvider 18 | - RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider 19 | - TomatoPHP\FilamentSaasPanel\FilamentSaasPanelServiceProvider 20 | - TomatoPHP\FilamentSaasPanel\Tests\AdminPanelProvider 21 | - TomatoPHP\FilamentSaasPanel\Tests\AppPanelProvider 22 | workbench: 23 | welcome: true 24 | install: true 25 | start: / 26 | guard: testing 27 | discovers: 28 | web: true 29 | api: false 30 | commands: false 31 | views: true 32 | -------------------------------------------------------------------------------- /src/Actions/Jetstream/DeleteUser.php: -------------------------------------------------------------------------------- 1 | deleteTeams($user); 25 | $user->deleteProfilePhoto(); 26 | $user->tokens->each->delete(); 27 | $user->delete(); 28 | }); 29 | } 30 | 31 | /** 32 | * Delete the teams and team associations attached to the user. 33 | */ 34 | protected function deleteTeams(Account $user): void 35 | { 36 | $user->teams()->detach(); 37 | 38 | $user->ownedTeams->each(function (Team $team) { 39 | $this->deletesTeams->delete($team); 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /module.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FilamentSaasPanel", 3 | "alias": "filament-saas-panel", 4 | "description": { 5 | "ar": "Ready to use SaaS panel with integration of Filament Accounts Builder and Jetsteam teams", 6 | "en": "Ready to use SaaS panel with integration of Filament Accounts Builder and Jetsteam teams", 7 | "gr": "Ready to use SaaS panel with integration of Filament Accounts Builder and Jetsteam teams", 8 | "sp": "Ready to use SaaS panel with integration of Filament Accounts Builder and Jetsteam teams" 9 | }, 10 | "keywords": [], 11 | "priority": 0, 12 | "providers": [ 13 | "TomatoPHP\\FilamentSaasPanel\\FilamentSaasPanelServiceProvider" 14 | ], 15 | "files": [], 16 | "title": { 17 | "ar": "SaaS Panel", 18 | "en": "SaaS Panel", 19 | "gr": "SaaS Panel", 20 | "sp": "SaaS Panel" 21 | }, 22 | "color": "#cc1448", 23 | "icon": "heroicon-c-users", 24 | "placeholder": "https://raw.githubusercontent.com/tomatophp/filament-saas-panel/master/arts/3x1io-tomato-saas-panel.jpg", 25 | "type": "plugin", 26 | "version": "v1.0.1", 27 | "github" : "https://github.com/tomatophp/filament-saas-panel", 28 | "docs" : "https://github.com/tomatophp/filament-saas-panel" 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/TestRegisterPage.php: -------------------------------------------------------------------------------- 1 | set('filament-saas-panel.user_model', \TomatoPHP\FilamentSaasPanel\Tests\Models\User::class); 9 | 10 | config()->set('filament-saas-panel.team_model', \TomatoPHP\FilamentSaasPanel\Tests\Models\Team::class); 11 | 12 | config()->set('filament-saas-panel.auth_guard', 'web'); 13 | 14 | $this->panel = Filament::getCurrentOrDefaultPanel(); 15 | }); 16 | 17 | it('can render register page', function () { 18 | get(url(config('filament-saas-panel.id').'/register'))->assertOk(); 19 | }); 20 | 21 | it('can register', function () { 22 | \Pest\Livewire\livewire(\TomatoPHP\FilamentSaasPanel\Filament\Pages\Auth\RegisterAccountWithoutOTP::class) 23 | ->fillForm([ 24 | 'name' => 'Fady Mondy', 25 | 'email' => 'info@3x1.io', 26 | 'password' => 'password', 27 | 'passwordConfirmation' => 'password', 28 | ]) 29 | ->call('register') 30 | ->assertHasNoFormErrors(); 31 | 32 | \Pest\Laravel\assertDatabaseHas(\TomatoPHP\FilamentSaasPanel\Tests\Models\User::class, [ 33 | 'name' => 'Fady Mondy', 34 | 'email' => 'info@3x1.io', 35 | ]); 36 | }); 37 | -------------------------------------------------------------------------------- /src/Traits/InteractsWithTenant.php: -------------------------------------------------------------------------------- 1 | teams; 30 | } 31 | 32 | public function canAccessTenant(Model $tenant): bool 33 | { 34 | return $this->teams()->whereKey($tenant)->exists(); 35 | } 36 | 37 | public function getFilamentAvatarUrl(): ?string 38 | { 39 | return (! empty($this->getFirstMediaUrl('avatar')) ? url($this->getFirstMediaUrl('avatar')) : null) ?: 'https://ui-avatars.com/api/?name='.str($this->name)->replace(' ', '+')->toString().'&color=FFFFFF&background=020617'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Filament/Resources/TeamResource/Actions/TeamTableAction.php: -------------------------------------------------------------------------------- 1 | iconButton() 15 | ->color('info') 16 | ->tooltip(trans('filament-saas-panel::messages.actions.edit.label')) 17 | ->icon('heroicon-s-user-group') 18 | ->fillForm(fn ($record) => [ 19 | 'teams' => $record->teams->pluck('id')->toArray(), 20 | ]) 21 | ->form([ 22 | Select::make('teams') 23 | ->columnSpanFull() 24 | ->multiple() 25 | ->searchable() 26 | ->preload() 27 | ->relationship('teams', 'name'), 28 | ]) 29 | ->action(function (array $data, $record) { 30 | Notification::make() 31 | ->body(trans('filament-saas-panel::messages.actions.edit.notification')) 32 | ->success() 33 | ->send(); 34 | }); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/TestEditTeamPage.php: -------------------------------------------------------------------------------- 1 | create(); 8 | $team = $account->teams()->create([ 9 | 'user_id' => $account->id, 10 | 'name' => 'Team 1', 11 | 'personal_team' => true, 12 | ]); 13 | $account->current_team_id = $team->id; 14 | actingAs($account, config('filament-saas-panel.auth_guard')); 15 | }); 16 | 17 | it('can render edit team page', function () { 18 | get(\TomatoPHP\FilamentSaasPanel\Filament\Pages\EditTeam::getUrl(['tenant' => auth(config('filament-saas-panel.auth_guard'))->user()->current_team_id]))->assertOk(); 19 | }); 20 | 21 | it('can edit team details', function () { 22 | filament()->setTenant(auth(config('filament-saas-panel.auth_guard'))->user()->currentTeam); 23 | 24 | \Pest\Livewire\livewire(\TomatoPHP\FilamentSaasPanel\Filament\Pages\EditTeam::class) 25 | ->fillForm([ 26 | 'name' => 'Team 2', 27 | ], 'editTeamForm') 28 | ->call('saveEditTeam'); 29 | 30 | \Pest\Laravel\assertDatabaseHas(\TomatoPHP\FilamentSaasPanel\Models\Team::class, [ 31 | 'name' => 'Team 2', 32 | 'user_id' => auth(config('filament-saas-panel.auth_guard'))->user()->id, 33 | ]); 34 | }); 35 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasEditTeam.php: -------------------------------------------------------------------------------- 1 | schema([ 17 | Section::make(trans('filament-saas-panel::messages.teams.edit.title')) 18 | ->description(trans('filament-saas-panel::messages.teams.edit.description')) 19 | ->schema(UpdateTeamForm::get(Filament::getTenant())), 20 | ]) 21 | ->model(Filament::getTenant()) 22 | ->statePath('editTeamData'); 23 | } 24 | 25 | public function saveEditTeam() 26 | { 27 | try { 28 | $data = $this->editTeamForm->getState(); 29 | 30 | $this->handleRecordUpdate(Filament::getTenant(), $data); 31 | } catch (Halt $exception) { 32 | return; 33 | } 34 | 35 | $this->sendSuccessNotification(); 36 | } 37 | 38 | protected function handleRecordUpdate(Model $record, array $data): Model 39 | { 40 | $record->update($data); 41 | 42 | return $record; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/migrations/2024_10_28_143941_add_media_if_not_exists_table copy.php: -------------------------------------------------------------------------------- 1 | id(); 19 | 20 | $table->morphs('model'); 21 | $table->uuid()->nullable()->unique(); 22 | $table->string('collection_name'); 23 | $table->string('name'); 24 | $table->string('file_name'); 25 | $table->string('mime_type')->nullable(); 26 | $table->string('disk'); 27 | $table->string('conversions_disk')->nullable(); 28 | $table->unsignedBigInteger('size'); 29 | $table->json('manipulations'); 30 | $table->json('custom_properties'); 31 | $table->json('generated_conversions'); 32 | $table->json('responsive_images'); 33 | $table->unsignedInteger('order_column')->nullable()->index(); 34 | 35 | $table->nullableTimestamps(); 36 | }); 37 | } 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /tests/database/migrations/2024_10_28_143941_add_media_if_not_exists_table.php: -------------------------------------------------------------------------------- 1 | id(); 19 | 20 | $table->morphs('model'); 21 | $table->uuid()->nullable()->unique(); 22 | $table->string('collection_name'); 23 | $table->string('name'); 24 | $table->string('file_name'); 25 | $table->string('mime_type')->nullable(); 26 | $table->string('disk'); 27 | $table->string('conversions_disk')->nullable(); 28 | $table->unsignedBigInteger('size'); 29 | $table->json('manipulations'); 30 | $table->json('custom_properties'); 31 | $table->json('generated_conversions'); 32 | $table->json('responsive_images'); 33 | $table->unsignedInteger('order_column')->nullable()->index(); 34 | 35 | $table->nullableTimestamps(); 36 | }); 37 | } 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditProfile/HasEditProfile.php: -------------------------------------------------------------------------------- 1 | schema(EditProfileForm::get()) 17 | ->model($this->getUser()) 18 | ->statePath('profileData'); 19 | } 20 | 21 | protected function getUpdateProfileFormActions(): array 22 | { 23 | return [ 24 | Action::make('getUpdateProfileFormActions') 25 | ->label(trans('filament-saas-panel::messages.save')) 26 | ->submit('editProfileForm'), 27 | ]; 28 | } 29 | 30 | public function updateProfile(): void 31 | { 32 | try { 33 | $data = $this->editProfileForm->getState(); 34 | 35 | $this->handleRecordUpdate($this->getUser(), $data); 36 | } catch (Halt $exception) { 37 | return; 38 | } 39 | 40 | $this->sendSuccessNotification(); 41 | } 42 | 43 | protected function handleRecordUpdate(Model $record, array $data): Model 44 | { 45 | $record->update($data); 46 | 47 | return $record; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditProfile/HasEditPassword.php: -------------------------------------------------------------------------------- 1 | schema(EditPasswordForm::get()) 17 | ->model($this->getUser()) 18 | ->statePath('passwordData'); 19 | } 20 | 21 | protected function getUpdatePasswordFormActions(): array 22 | { 23 | return [ 24 | Action::make('getUpdatePasswordFormActions') 25 | ->label(trans('filament-saas-panel::messages.save')) 26 | ->submit('editPasswordForm'), 27 | ]; 28 | } 29 | 30 | public function updatePassword(): void 31 | { 32 | try { 33 | $data = $this->editPasswordForm->getState(); 34 | 35 | $this->handleRecordUpdate($this->getUser(), $data); 36 | } catch (Halt $exception) { 37 | return; 38 | } 39 | 40 | if (request()->hasSession() && array_key_exists('password', $data)) { 41 | request()->session()->put([ 42 | 'password_hash_'.Filament::getAuthGuard() => $data['password'], 43 | ]); 44 | } 45 | 46 | $this->editPasswordForm->fill(); 47 | 48 | $this->sendSuccessNotification(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Filament/Resources/TeamResource/Actions/TeamBulkAction.php: -------------------------------------------------------------------------------- 1 | color('info') 17 | ->tooltip(trans('filament-saas-panel::messages.actions.edit.label')) 18 | ->label(trans('filament-saas-panel::messages.actions.edit.label')) 19 | ->icon('heroicon-s-user-group') 20 | ->form([ 21 | Select::make('teams') 22 | ->columnSpanFull() 23 | ->multiple() 24 | ->searchable() 25 | ->preload() 26 | ->options(Team::query()->pluck('name', 'id')->toArray()), 27 | ]) 28 | ->deselectRecordsAfterCompletion() 29 | ->action(function (array $data, Collection $record) { 30 | $record->each(function ($account) use ($data) { 31 | $account->teams()->sync($data['teams']); 32 | }); 33 | 34 | Notification::make() 35 | ->body(trans('filament-saas-panel::messages.actions.edit.notification')) 36 | ->success() 37 | ->send(); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/TestLoginPage.php: -------------------------------------------------------------------------------- 1 | set('filament-saas-panel.user_model', \TomatoPHP\FilamentSaasPanel\Tests\Models\User::class); 10 | 11 | config()->set('filament-saas-panel.team_model', \TomatoPHP\FilamentSaasPanel\Tests\Models\Team::class); 12 | 13 | config()->set('filament-saas-panel.auth_guard', 'web'); 14 | 15 | $this->panel = Filament::getCurrentOrDefaultPanel(); 16 | $this->panel->tenant(Team::class, 'id'); 17 | }); 18 | 19 | it('can render login page', function () { 20 | get(url(config('filament-saas-panel.id').'/login'))->assertOk(); 21 | }); 22 | 23 | // it('can login', function () { 24 | // $account = \TomatoPHP\FilamentSaasPanel\Tests\Models\User::factory()->create(); 25 | // $team =Team::create([ 26 | // 'user_id' => $account->id, 27 | // 'name' => 'Team 1', 28 | // 'personal_team' => true, 29 | // ]); 30 | // $account->current_team_id = $team->id; 31 | // $account->is_active = true; 32 | // $account->save(); 33 | 34 | // $team->users()->attach($account, ['role' => 'admin']); 35 | 36 | // \Pest\Livewire\livewire(\TomatoPHP\FilamentSaasPanel\Filament\Pages\Auth\LoginAccount::class) 37 | // ->fillForm([ 38 | // 'email' => $account->email, 39 | // 'password' => 'password', 40 | // ]) 41 | // ->call('authenticate'); 42 | 43 | // expect(auth(config('filament-saas-panel.auth_guard'))->check())->toBeTrue(); 44 | // }); 45 | -------------------------------------------------------------------------------- /src/Http/Controllers/TeamsController.php: -------------------------------------------------------------------------------- 1 | first(); 18 | 19 | if ($invitation) { 20 | $newTeamMember = Jetstream::findUserByEmailOrFail($invitation->email); 21 | 22 | AddingTeamMember::dispatch($invitation->team, $newTeamMember); 23 | 24 | $invitation->team->users()->attach( 25 | $newTeamMember, ['role' => $invitation->role] 26 | ); 27 | 28 | TeamMemberAdded::dispatch($invitation->team, $newTeamMember); 29 | 30 | $invitation->delete(); 31 | 32 | return redirect()->to(url(Filament::getCurrentOrDefaultPanel()->getId().'/'.$invitation->team->id)); 33 | } 34 | 35 | return redirect()->to(url(Filament::getCurrentOrDefaultPanel()->getId())); 36 | } 37 | 38 | public function cancel(Request $request, $invitationId) 39 | { 40 | $model = Jetstream::teamInvitationModel(); 41 | 42 | $invitation = $model::whereKey($invitationId)->first(); 43 | 44 | if ($invitation) { 45 | $invitation->delete(); 46 | } 47 | 48 | return redirect()->to(url(Filament::getCurrentOrDefaultPanel()->getId())); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /publish/Team.php: -------------------------------------------------------------------------------- 1 | 24 | */ 25 | protected $fillable = [ 26 | 'account_id', 27 | 'name', 28 | 'personal_team', 29 | ]; 30 | 31 | /** 32 | * The event map for the model. 33 | * 34 | * @var array 35 | */ 36 | protected $dispatchesEvents = [ 37 | 'created' => TeamCreated::class, 38 | 'updated' => TeamUpdated::class, 39 | 'deleted' => TeamDeleted::class, 40 | ]; 41 | 42 | /** 43 | * Get the attributes that should be cast. 44 | * 45 | * @return array 46 | */ 47 | protected function casts(): array 48 | { 49 | return [ 50 | 'personal_team' => 'boolean', 51 | ]; 52 | } 53 | 54 | public function getFilamentAvatarUrl(): ?string 55 | { 56 | return $this->getFirstMediaUrl('avatar') ?: null; 57 | } 58 | 59 | public function owner(): BelongsTo 60 | { 61 | return $this->belongsTo(Account::class, 'account_id'); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Filament/Pages/CreateTeam.php: -------------------------------------------------------------------------------- 1 | schema([ 29 | FileUpload::make('avatar') 30 | ->disk(config('filesystems.default')) 31 | ->alignCenter() 32 | ->avatar(), 33 | TextInput::make('name') 34 | ->default(auth(config('filament-saas-panel.auth_guard'))->user()->teams()->count() > 0 ? null : auth(config('filament-saas-panel.auth_guard'))->user()->name."'s Team"), 35 | ]); 36 | } 37 | 38 | protected function handleRegistration(array $data): Model 39 | { 40 | $newTeam = app(\TomatoPHP\FilamentSaasPanel\Actions\Jetstream\CreateTeam::class) 41 | ->create(auth(config('filament-saas-panel.auth_guard'))->user(), $data); 42 | 43 | if (isset($data['avatar'])) { 44 | $newTeam->addMediaFromDisk($data['avatar'], config('filesystems.default')) 45 | ->usingName($data['name']) 46 | ->toMediaCollection('avatar'); 47 | } 48 | 49 | return $newTeam; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Filament/Forms/EditProfileForm.php: -------------------------------------------------------------------------------- 1 | description(trans('filament-saas-panel::messages.profile.edit.description')) 16 | ->schema([ 17 | Forms\Components\SpatieMediaLibraryFileUpload::make('avatar') 18 | ->avatar() 19 | ->alignCenter() 20 | ->circleCropper() 21 | ->collection('avatar') 22 | ->columnSpan(2) 23 | ->label(trans('filament-saas-panel::messages.profile.edit.avatar')), 24 | Forms\Components\TextInput::make('name') 25 | ->columnSpan(2) 26 | ->label(trans('filament-saas-panel::messages.profile.edit.name')) 27 | ->required(), 28 | Forms\Components\TextInput::make('email') 29 | ->columnSpan(2) 30 | ->label(trans('filament-saas-panel::messages.profile.edit.email')) 31 | ->email() 32 | ->required() 33 | ->unique(ignoreRecord: true), 34 | Action::make('getUpdateProfileFormActions') 35 | ->label(trans('filament-saas-panel::messages.save')) 36 | ->submit('editProfileForm'), 37 | ]), 38 | ]; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Actions/Jetstream/RemoveTeamMember.php: -------------------------------------------------------------------------------- 1 | authorize($user, $team, $teamMember); 21 | 22 | $this->ensureUserDoesNotOwnTeam($teamMember, $team); 23 | 24 | $team->removeUser($teamMember); 25 | 26 | TeamMemberRemoved::dispatch($team, $teamMember); 27 | } 28 | 29 | /** 30 | * Authorize that the user can remove the team member. 31 | */ 32 | protected function authorize(Account $user, Team $team, Account $teamMember): void 33 | { 34 | if (! Gate::forUser($user)->check('removeTeamMember', $team) && 35 | $user->id !== $teamMember->id) { 36 | throw new AuthorizationException; 37 | } 38 | } 39 | 40 | /** 41 | * Ensure that the currently authenticated user does not own the team. 42 | */ 43 | protected function ensureUserDoesNotOwnTeam(Account $teamMember, Team $team): void 44 | { 45 | if ($teamMember->id === $team->owner->id) { 46 | throw ValidationException::withMessages([ 47 | 'team' => [__('You may not leave a team that you created.')], 48 | ])->errorBag('removeTeamMember'); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasLeavingTeam.php: -------------------------------------------------------------------------------- 1 | requiresConfirmation() 16 | ->link() 17 | ->color('danger') 18 | ->label(trans('filament-saas-panel::messages.teams.members.leave_team')) 19 | ->action(function (array $arguments) { 20 | $this->removeMember($arguments['user']); 21 | }); 22 | } 23 | 24 | public function getRemoveMemberAction(): Action 25 | { 26 | return Action::make('getRemoveMemberAction') 27 | ->requiresConfirmation() 28 | ->link() 29 | ->color('danger') 30 | ->label(trans('filament-saas-panel::messages.teams.members.remove_member')) 31 | ->action(function (array $arguments) { 32 | $this->removeMember($arguments['user']); 33 | }); 34 | } 35 | 36 | public function removeMember($user) 37 | { 38 | $teamMember = config('filament-saas-panel.user_model')::find($user); 39 | try { 40 | Filament::getTenant()->removeUser($teamMember); 41 | TeamMemberRemoved::dispatch(Filament::getTenant(), $teamMember); 42 | $teamMember->current_team_id = $teamMember->teams()->first()?->id ?? null; 43 | } catch (Halt $exception) { 44 | return; 45 | } 46 | 47 | $this->sendSuccessNotification(); 48 | 49 | return redirect()->to(Filament::getCurrentOrDefaultPanel()->getUrl()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Filament/Forms/UpdateTeamForm.php: -------------------------------------------------------------------------------- 1 | label(trans('filament-saas-panel::messages.teams.edit.owner')) 18 | ->hiddenLabel() 19 | ->view('filament-saas-panel::forms.components.team-owner', ['team' => $team]), 20 | SpatieMediaLibraryFileUpload::make('avatar') 21 | ->avatar() 22 | ->label(trans('filament-saas-panel::messages.teams.edit.avatar')) 23 | ->disabled(fn () => auth(config('filament-saas-panel.auth_guard'))->user()->id !== $team->{config('filament-saas-panel.team_id_column')}) 24 | ->collection('avatar'), 25 | TextInput::make('name') 26 | ->label(trans('filament-saas-panel::messages.teams.edit.name')) 27 | ->disabled(fn () => auth(config('filament-saas-panel.auth_guard'))->user()->id !== $team->{config('filament-saas-panel.team_id_column')}) 28 | ->required(), 29 | Action::make('editTeam') 30 | ->requiresConfirmation() 31 | ->label(trans('filament-saas-panel::messages.teams.edit.save')) 32 | ->submit('editTeamForm') 33 | ->color('primary'), 34 | ]; 35 | } 36 | 37 | public static function sendErrorDeleteAccount(string $message): void 38 | { 39 | Notification::make() 40 | ->danger() 41 | ->title($message) 42 | ->send(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/src/TestEditProfilePage.php: -------------------------------------------------------------------------------- 1 | create(); 8 | $team = $account->teams()->create([ 9 | 'user_id' => $account->id, 10 | 'name' => 'Team 1', 11 | 'personal_team' => true, 12 | ]); 13 | $account->current_team_id = $team->id; 14 | actingAs($account, config('filament-saas-panel.auth_guard')); 15 | }); 16 | 17 | it('can render edit profile page', function () { 18 | get(\TomatoPHP\FilamentSaasPanel\Filament\Pages\EditProfile::getUrl(['tenant' => auth(config('filament-saas-panel.auth_guard'))->user()->current_team_id]))->assertOk(); 19 | }); 20 | 21 | it('can edit profile details', function () { 22 | \Pest\Livewire\livewire(\TomatoPHP\FilamentSaasPanel\Filament\Pages\EditProfile::class) 23 | ->fillForm([ 24 | 'name' => 'John Doe', 25 | ], 'editProfileForm') 26 | ->call('updateProfile'); 27 | 28 | \Pest\Laravel\assertDatabaseHas(\TomatoPHP\FilamentSaasPanel\Tests\Models\User::class, [ 29 | 'id' => auth(config('filament-saas-panel.auth_guard'))->user()->id, 30 | 'name' => 'John Doe', 31 | ]); 32 | }); 33 | 34 | it('can edit profile password', function () { 35 | \Pest\Livewire\livewire(\TomatoPHP\FilamentSaasPanel\Filament\Pages\EditProfile::class) 36 | ->fillForm([ 37 | 'current_password' => 'password', 38 | 'password' => 'password123', 39 | 'passwordConfirmation' => 'password123', 40 | ], 'editPasswordForm') 41 | ->call('updatePassword'); 42 | 43 | \PHPUnit\Framework\assertTrue(auth(config('filament-saas-panel.auth_guard'))->attempt([ 44 | 'email' => auth(config('filament-saas-panel.auth_guard'))->user()->email, 45 | 'password' => 'password123', 46 | ])); 47 | }); 48 | -------------------------------------------------------------------------------- /src/Actions/Fortify/CreateNewUser.php: -------------------------------------------------------------------------------- 1 | $input 21 | */ 22 | public function create(array $input): Account 23 | { 24 | Validator::make($input, [ 25 | 'name' => ['required', 'string', 'max:255'], 26 | 'email' => ['required', 'string', 'email', 'max:255', 'unique:accounts'], 27 | 'password' => $this->passwordRules(), 28 | 'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '', 29 | ])->validate(); 30 | 31 | return DB::transaction(function () use ($input) { 32 | return tap(Account::query()->create([ 33 | 'name' => $input['name'], 34 | 'email' => $input['email'], 35 | 'loginBy' => 'email', 36 | 'type' => 'account', 37 | 'password' => Hash::make($input['password']), 38 | ]), function (Account $user) { 39 | $this->createTeam($user); 40 | }); 41 | }); 42 | } 43 | 44 | /** 45 | * Create a personal team for the user. 46 | */ 47 | protected function createTeam(Account $user): void 48 | { 49 | $user->ownedTeams()->save(Team::forceCreate([ 50 | 'account_id' => $user->id, 51 | 'name' => explode(' ', $user->name, 2)[0]."'s Team", 52 | 'personal_team' => true, 53 | ])); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/src/AdminPanelProvider.php: -------------------------------------------------------------------------------- 1 | id('admin') 26 | ->path('admin') 27 | ->login() 28 | ->pages([ 29 | Pages\Dashboard::class, 30 | ]) 31 | ->plugin( 32 | FilamentSaasTeamsPlugin::make() 33 | ->allowAccountTeamTableAction() 34 | ->allowAccountTeamTableBulkAction() 35 | ->allowAccountTeamFilter() 36 | ->allowAccountTeamFormComponent() 37 | ->allowAccountTeamTableColumn() 38 | ) 39 | ->middleware([ 40 | EncryptCookies::class, 41 | AddQueuedCookiesToResponse::class, 42 | StartSession::class, 43 | AuthenticateSession::class, 44 | ShareErrorsFromSession::class, 45 | VerifyCsrfToken::class, 46 | SubstituteBindings::class, 47 | DisableBladeIconComponents::class, 48 | DispatchServingFilamentEvent::class, 49 | ]) 50 | ->authMiddleware([ 51 | Authenticate::class, 52 | ]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/src/TestTeamsResource.php: -------------------------------------------------------------------------------- 1 | create(), 'web'); 14 | 15 | $panel = filament()->getPanels()['admin']; 16 | filament()->setCurrentPanel($panel); 17 | }); 18 | 19 | it('can render teams resource', function () { 20 | get(TeamResource::getUrl())->assertSuccessful(); 21 | }); 22 | 23 | it('can list teams', function () { 24 | Team::query()->delete(); 25 | $teams = Team::factory()->count(10)->create(); 26 | 27 | livewire(Pages\ListTeams::class) 28 | ->loadTable() 29 | ->assertCanSeeTableRecords($teams) 30 | ->assertCountTableRecords(10); 31 | }); 32 | 33 | it('can render teams name/avatar column in table', function () { 34 | Team::factory()->count(10)->create(); 35 | 36 | livewire(Pages\ListTeams::class) 37 | ->loadTable() 38 | ->assertCanRenderTableColumn('name') 39 | ->assertCanRenderTableColumn('avatar'); 40 | }); 41 | 42 | it('can render teams list page', function () { 43 | livewire(Pages\ListTeams::class)->assertSuccessful(); 44 | }); 45 | 46 | it('can render view teams action', function () { 47 | livewire(Pages\ListTeams::class, [ 48 | 'record' => Team::factory()->create(), 49 | ]) 50 | ->mountAction('view') 51 | ->assertSuccessful(); 52 | }); 53 | 54 | it('can render team create action', function () { 55 | livewire(Pages\ListTeams::class) 56 | ->mountAction('create') 57 | ->assertSuccessful(); 58 | }); 59 | 60 | it('can render team edit action', function () { 61 | livewire(Pages\ListTeams::class, [ 62 | 'record' => Team::factory()->create(), 63 | ]) 64 | ->mountAction('edit') 65 | ->assertSuccessful(); 66 | }); 67 | -------------------------------------------------------------------------------- /src/Actions/Fortify/UpdateUserProfileInformation.php: -------------------------------------------------------------------------------- 1 | $input 17 | */ 18 | public function update(Account $user, array $input): void 19 | { 20 | Validator::make($input, [ 21 | 'name' => ['required', 'string', 'max:255'], 22 | 'email' => ['required', 'email', 'max:255', Rule::unique('accounts')->ignore($user->id)], 23 | 'phone' => ['required', 'max:255', Rule::unique('accounts')->ignore($user->id)], 24 | 'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'], 25 | ])->validateWithBag('updateProfileInformation'); 26 | 27 | if (isset($input['photo'])) { 28 | $user->updateProfilePhoto($input['photo']); 29 | } 30 | 31 | if ($input['email'] !== $user->email && 32 | $user instanceof MustVerifyEmail) { 33 | $this->updateVerifiedUser($user, $input); 34 | } else { 35 | $user->forceFill([ 36 | 'name' => $input['name'], 37 | 'email' => $input['email'], 38 | 'phone' => $input['phone'], 39 | ])->save(); 40 | } 41 | } 42 | 43 | /** 44 | * Update the given verified user's profile information. 45 | * 46 | * @param array $input 47 | */ 48 | protected function updateVerifiedUser(Account $user, array $input): void 49 | { 50 | $user->forceFill([ 51 | 'name' => $input['name'], 52 | 'email' => $input['email'], 53 | 'phone' => $input['phone'], 54 | ])->save(); 55 | 56 | $user->sendEmailVerificationNotification(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Filament/Forms/EditPasswordForm.php: -------------------------------------------------------------------------------- 1 | description(trans('filament-saas-panel::messages.profile.password.description')) 18 | ->schema([ 19 | Forms\Components\TextInput::make('current_password') 20 | ->label(trans('filament-saas-panel::messages.profile.password.current_password')) 21 | ->password() 22 | ->required() 23 | ->currentPassword() 24 | ->revealable(), 25 | Forms\Components\TextInput::make('password') 26 | ->label(trans('filament-saas-panel::messages.profile.password.new_password')) 27 | ->password() 28 | ->required() 29 | ->rule(Password::default()) 30 | ->autocomplete('new-password') 31 | ->dehydrateStateUsing(fn ($state): string => Hash::make($state)) 32 | ->live(debounce: 500) 33 | ->same('passwordConfirmation') 34 | ->revealable(), 35 | Forms\Components\TextInput::make('passwordConfirmation') 36 | ->label(trans('filament-saas-panel::messages.profile.password.confirm_password')) 37 | ->password() 38 | ->required() 39 | ->dehydrated(false) 40 | ->revealable(), 41 | Action::make('getUpdatePasswordFormActions') 42 | ->label(trans('filament-saas-panel::messages.save')) 43 | ->submit('editPasswordForm'), 44 | ]), 45 | ]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/FilamentSaasTeamsPlugin.php: -------------------------------------------------------------------------------- 1 | allowAccountTeamTableAction = $allowAccountTeamTableAction; 29 | 30 | return $this; 31 | } 32 | 33 | public function allowAccountTeamTableBulkAction(bool $allowAccountTeamTableBulkAction = true): self 34 | { 35 | $this->allowAccountTeamTableBulkAction = $allowAccountTeamTableBulkAction; 36 | 37 | return $this; 38 | } 39 | 40 | public function allowAccountTeamFilter(bool $allowAccountTeamFilter = true): self 41 | { 42 | $this->allowAccountTeamFilter = $allowAccountTeamFilter; 43 | 44 | return $this; 45 | } 46 | 47 | public function allowAccountTeamFormComponent(bool $allowAccountTeamFormComponent = true): self 48 | { 49 | $this->allowAccountTeamFormComponent = $allowAccountTeamFormComponent; 50 | 51 | return $this; 52 | } 53 | 54 | public function allowAccountTeamTableColumn(bool $allowAccountTeamTableColumn = true): self 55 | { 56 | $this->allowAccountTeamTableColumn = $allowAccountTeamTableColumn; 57 | 58 | return $this; 59 | } 60 | 61 | public function register(Panel $panel): void 62 | { 63 | $panel->resources([ 64 | TeamResource::class, 65 | ]); 66 | } 67 | 68 | public function boot(Panel $panel): void 69 | { 70 | // 71 | } 72 | 73 | public static function make(): FilamentSaasTeamsPlugin 74 | { 75 | return new FilamentSaasTeamsPlugin; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Report an Issue or Bug with the Package 3 | title: "[Bug]: " 4 | labels: ["bug"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | We're sorry to hear you have a problem. Can you help us solve it by providing the following details. 10 | - type: textarea 11 | id: what-happened 12 | attributes: 13 | label: What happened? 14 | description: What did you expect to happen? 15 | placeholder: I cannot currently do X thing because when I do, it breaks X thing. 16 | validations: 17 | required: true 18 | - type: textarea 19 | id: how-to-reproduce 20 | attributes: 21 | label: How to reproduce the bug 22 | description: How did this occur, please add any config values used and provide a set of reliable steps if possible. 23 | placeholder: When I do X I see Y. 24 | validations: 25 | required: true 26 | - type: input 27 | id: package-version 28 | attributes: 29 | label: Package Version 30 | description: What version of our Package are you running? Please be as specific as possible 31 | placeholder: 2.0.0 32 | validations: 33 | required: true 34 | - type: input 35 | id: php-version 36 | attributes: 37 | label: PHP Version 38 | description: What version of PHP are you running? Please be as specific as possible 39 | placeholder: 8.2.0 40 | validations: 41 | required: true 42 | - type: input 43 | id: laravel-version 44 | attributes: 45 | label: Laravel Version 46 | description: What version of Laravel are you running? Please be as specific as possible 47 | placeholder: 9.0.0 48 | validations: 49 | required: true 50 | - type: dropdown 51 | id: operating-systems 52 | attributes: 53 | label: Which operating systems does with happen with? 54 | description: You may select more than one. 55 | multiple: true 56 | options: 57 | - macOS 58 | - Windows 59 | - Linux 60 | - type: textarea 61 | id: notes 62 | attributes: 63 | label: Notes 64 | description: Use this field to provide any other notes that you feel might be relevant to the issue. 65 | validations: 66 | required: false 67 | -------------------------------------------------------------------------------- /tests/src/Models/User.php: -------------------------------------------------------------------------------- 1 | 27 | */ 28 | protected $fillable = [ 29 | 'name', 30 | 'email', 31 | 'phone', 32 | 'username', 33 | 'loginBy', 34 | 'type', 35 | 'address', 36 | 'password', 37 | 'profile_photo_path', 38 | ]; 39 | 40 | /** 41 | * The attributes that should be hidden for serialization. 42 | * 43 | * @var array 44 | */ 45 | protected $hidden = [ 46 | 'password', 47 | 'remember_token', 48 | 'two_factor_recovery_codes', 49 | 'two_factor_secret', 50 | ]; 51 | 52 | /** 53 | * The accessors to append to the model's array form. 54 | * 55 | * @var array 56 | */ 57 | protected $appends = [ 58 | 'profile_photo_url', 59 | ]; 60 | 61 | /** 62 | * Get the attributes that should be cast. 63 | * 64 | * @return array 65 | */ 66 | protected function casts(): array 67 | { 68 | return [ 69 | 'email_verified_at' => 'datetime', 70 | 'password' => 'hashed', 71 | ]; 72 | } 73 | 74 | public function canAccessPanel(Panel $panel): bool 75 | { 76 | return true; 77 | } 78 | 79 | protected static function newFactory(): UserFactory 80 | { 81 | return UserFactory::new(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam.php: -------------------------------------------------------------------------------- 1 | fillForms(); 48 | } 49 | 50 | protected function getForms(): array 51 | { 52 | return [ 53 | 'editTeamForm', 54 | 'deleteTeamFrom', 55 | 'manageTeamMembersForm', 56 | ]; 57 | } 58 | 59 | protected function fillForms(): void 60 | { 61 | $data = Filament::getTenant(); 62 | 63 | $this->editTeamForm->fill($data->toArray()); 64 | $this->deleteTeamFrom->fill($data->toArray()); 65 | $this->manageTeamMembersForm->fill($data->toArray()); 66 | } 67 | 68 | protected function getViewData(): array 69 | { 70 | return [ 71 | 'team' => Filament::getTenant(), 72 | ]; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/src/AppPanelProvider.php: -------------------------------------------------------------------------------- 1 | default() 26 | ->id('app') 27 | ->path('app') 28 | ->login() 29 | ->pages([ 30 | Pages\Dashboard::class, 31 | ]) 32 | ->plugin( 33 | FilamentSaasPanelPlugin::make() 34 | ->editTeam() 35 | ->deleteTeam() 36 | ->showTeamMembers() 37 | ->teamInvitation() 38 | ->allowTenants() 39 | ->checkAccountStatusInLogin() 40 | ->APITokenManager() 41 | ->editProfile() 42 | ->editPassword() 43 | ->browserSessionManager() 44 | ->deleteAccount() 45 | ->editProfileMenu() 46 | ->registration(), 47 | ) 48 | ->middleware([ 49 | EncryptCookies::class, 50 | AddQueuedCookiesToResponse::class, 51 | StartSession::class, 52 | AuthenticateSession::class, 53 | ShareErrorsFromSession::class, 54 | VerifyCsrfToken::class, 55 | SubstituteBindings::class, 56 | DisableBladeIconComponents::class, 57 | DispatchServingFilamentEvent::class, 58 | ]) 59 | ->authMiddleware([ 60 | Authenticate::class, 61 | ]); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: "Tests" 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - master 8 | paths: 9 | - '**.php' 10 | pull_request: 11 | types: 12 | - opened 13 | - synchronize 14 | branches: 15 | - master 16 | paths: 17 | - '**.php' 18 | - '.github/workflows/tests.yml' 19 | - 'phpunit.xml.dist' 20 | - 'composer.json' 21 | - 'composer.lock' 22 | 23 | jobs: 24 | test: 25 | runs-on: ${{ matrix.os }} 26 | strategy: 27 | fail-fast: true 28 | matrix: 29 | os: [ubuntu-latest] 30 | php: [8.4, 8.3, 8.2] 31 | laravel: [12.*, 11.*] 32 | stability: [prefer-stable] 33 | include: 34 | - laravel: 12.* 35 | testbench: 10.* 36 | carbon: 3.* 37 | collision: 8.* 38 | - laravel: 11.* 39 | testbench: 9.* 40 | carbon: 3.* 41 | collision: 8.* 42 | exclude: 43 | - laravel: 11.* 44 | php: 8.1 45 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} 46 | steps: 47 | - name: Checkout Code 48 | uses: actions/checkout@v5 49 | 50 | - name: Cache Dependencies 51 | uses: actions/cache@v4 52 | with: 53 | path: ~/.composer/cache/files 54 | key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 55 | 56 | - name: Setup PHP 57 | uses: shivammathur/setup-php@v2 58 | with: 59 | php-version: ${{ matrix.php }} 60 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo 61 | coverage: none 62 | 63 | - name: Install Dependencies 64 | run: | 65 | echo "::add-matcher::${{ runner.tool_cache }}/php.json" 66 | echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" 67 | 68 | - name: Install Dependencies 69 | run: | 70 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" "nunomaduro/collision:${{ matrix.collision }}" --no-interaction --no-update 71 | composer update --${{ matrix.stability }} --prefer-dist --no-interaction 72 | composer db 73 | 74 | - name: Execute tests 75 | run: vendor/bin/pest 76 | -------------------------------------------------------------------------------- /tests/src/Models/Team.php: -------------------------------------------------------------------------------- 1 | 26 | */ 27 | protected $fillable = [ 28 | 'user_id', 29 | 'name', 30 | 'personal_team', 31 | ]; 32 | 33 | /** 34 | * The event map for the model. 35 | * 36 | * @var array 37 | */ 38 | protected $dispatchesEvents = [ 39 | 'created' => TeamCreated::class, 40 | 'updated' => TeamUpdated::class, 41 | 'deleted' => TeamDeleted::class, 42 | ]; 43 | 44 | /** 45 | * Get the attributes that should be cast. 46 | * 47 | * @return array 48 | */ 49 | protected function casts(): array 50 | { 51 | return [ 52 | 'personal_team' => 'boolean', 53 | ]; 54 | } 55 | 56 | protected $appends = [ 57 | 'avatar', 58 | ]; 59 | 60 | public function getFilamentAvatarUrl(): ?string 61 | { 62 | return $this->getFirstMediaUrl('avatar') ?: null; 63 | } 64 | 65 | public function getAvatarAttribute(): string 66 | { 67 | return $this->getFirstMediaUrl('avatar') ?: 'https://ui-avatars.com/api/?name='.str($this->name)->replace(' ', '+')->toString().'&color=FFFFFF&background=020617'; 68 | } 69 | 70 | public function owner(): BelongsTo 71 | { 72 | return $this->belongsTo(User::class, 'user_id'); 73 | } 74 | 75 | public function accounts(): BelongsToMany 76 | { 77 | return $this->belongsToMany(User::class, 'team_user', 'team_id', 'user_id'); 78 | } 79 | 80 | protected static function newFactory(): TeamFactory 81 | { 82 | return TeamFactory::new(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Models/Team.php: -------------------------------------------------------------------------------- 1 | 25 | */ 26 | protected $fillable = [ 27 | 'account_id', 28 | 'name', 29 | 'personal_team', 30 | ]; 31 | 32 | /** 33 | * The event map for the model. 34 | * 35 | * @var array 36 | */ 37 | protected $dispatchesEvents = [ 38 | 'created' => TeamCreated::class, 39 | 'updated' => TeamUpdated::class, 40 | 'deleted' => TeamDeleted::class, 41 | ]; 42 | 43 | /** 44 | * Get the attributes that should be cast. 45 | * 46 | * @return array 47 | */ 48 | protected function casts(): array 49 | { 50 | return [ 51 | 'personal_team' => 'boolean', 52 | ]; 53 | } 54 | 55 | protected $appends = [ 56 | 'avatar', 57 | ]; 58 | 59 | public function getFilamentAvatarUrl(): ?string 60 | { 61 | return $this->getFirstMediaUrl('avatar') ?: 'https://ui-avatars.com/api/?name='.str($this->name)->replace(' ', '+')->toString().'&color=FFFFFF&background=020617'; 62 | } 63 | 64 | public function getAvatarAttribute(): string 65 | { 66 | return $this->getFirstMediaUrl('avatar') ?: 'https://ui-avatars.com/api/?name='.str($this->name)->replace(' ', '+')->toString().'&color=FFFFFF&background=020617'; 67 | } 68 | 69 | public function owner(): BelongsTo 70 | { 71 | return $this->belongsTo(config('filament-saas-panel.user_model'), config('filament-saas-panel.team_id_column')); 72 | } 73 | 74 | public function accounts(): BelongsToMany 75 | { 76 | return $this->belongsToMany(config('filament-saas-panel.user_model'), 'team_user', 'team_id', config('filament-saas-panel.team_id_column')); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /publish/Account.php: -------------------------------------------------------------------------------- 1 | 'boolean', 72 | 'is_active' => 'boolean', 73 | ]; 74 | 75 | protected $dates = [ 76 | 'deleted_at', 77 | 'created_at', 78 | 'updated_at', 79 | 'otp_activated_at', 80 | 'last_login', 81 | ]; 82 | 83 | protected $hidden = [ 84 | 'password', 85 | 'remember_token', 86 | 'otp_code', 87 | 'otp_activated_at', 88 | 'host', 89 | 'agent', 90 | ]; 91 | 92 | public function getFilamentAvatarUrl(): ?string 93 | { 94 | return $this->getFirstMediaUrl('avatar') ?? null; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Actions/Jetstream/AddTeamMember.php: -------------------------------------------------------------------------------- 1 | authorize('addTeamMember', $team); 24 | 25 | $this->validate($team, $email, $role); 26 | 27 | $newTeamMember = Jetstream::findUserByEmailOrFail($email); 28 | 29 | AddingTeamMember::dispatch($team, $newTeamMember); 30 | 31 | $team->users()->attach( 32 | $newTeamMember, ['role' => $role] 33 | ); 34 | 35 | TeamMemberAdded::dispatch($team, $newTeamMember); 36 | } 37 | 38 | /** 39 | * Validate the add member operation. 40 | */ 41 | protected function validate(Team $team, string $email, ?string $role): void 42 | { 43 | Validator::make([ 44 | 'email' => $email, 45 | 'role' => $role, 46 | ], $this->rules(), [ 47 | 'email.exists' => __('We were unable to find a registered user with this email address.'), 48 | ])->after( 49 | $this->ensureUserIsNotAlreadyOnTeam($team, $email) 50 | )->validateWithBag('addTeamMember'); 51 | } 52 | 53 | /** 54 | * Get the validation rules for adding a team member. 55 | */ 56 | protected function rules(): array 57 | { 58 | return array_filter([ 59 | 'email' => ['required', 'email', 'exists:accounts'], 60 | 'role' => Jetstream::hasRoles() 61 | ? ['required', 'string', new Role] 62 | : null, 63 | ]); 64 | } 65 | 66 | /** 67 | * Ensure that the user is not already on the team. 68 | */ 69 | protected function ensureUserIsNotAlreadyOnTeam(Team $team, string $email): Closure 70 | { 71 | return function ($validator) use ($team, $email) { 72 | $validator->errors()->addIf( 73 | $team->hasUserWithEmail($email), 74 | 'email', 75 | __('This user already belongs to the team.') 76 | ); 77 | }; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tomatophp/filament-saas-panel", 3 | "type": "library", 4 | "description": "Ready to use SaaS panel with integration of Filament Accounts Builder and JetStream teams", 5 | "keywords": [ 6 | "php", 7 | "laravel", 8 | "jetsteam", 9 | "fortify", 10 | "filament-plugin", 11 | "panel", 12 | "saas", 13 | "teams" 14 | ], 15 | "license": "MIT", 16 | "autoload": { 17 | "psr-4": { 18 | "TomatoPHP\\FilamentSaasPanel\\": "src/" 19 | } 20 | }, 21 | "autoload-dev": { 22 | "psr-4": { 23 | "TomatoPHP\\FilamentSaasPanel\\Tests\\": "tests/src/", 24 | "TomatoPHP\\FilamentSaasPanel\\Tests\\Database\\Factories\\": "tests/database/factories" 25 | } 26 | }, 27 | "extra": { 28 | "laravel": { 29 | "providers": [ 30 | "TomatoPHP\\FilamentSaasPanel\\FilamentSaasPanelServiceProvider" 31 | ] 32 | } 33 | }, 34 | "authors": [ 35 | { 36 | "name": "Fady Mondy", 37 | "email": "info@3x1.io" 38 | } 39 | ], 40 | "config": { 41 | "sort-packages": true, 42 | "allow-plugins": { 43 | "pestphp/pest-plugin": true, 44 | "phpstan/extension-installer": true 45 | } 46 | }, 47 | "scripts": { 48 | "testbench": "vendor/bin/testbench package:discover --ansi", 49 | "db": "vendor/bin/testbench package:create-sqlite-db && vendor/bin/testbench migrate", 50 | "analyse": "vendor/bin/phpstan analyse src tests", 51 | "test": "vendor/bin/pest", 52 | "test-coverage": "vendor/bin/pest --coverage", 53 | "format": "vendor/bin/pint" 54 | }, 55 | "require": { 56 | "php": "^8.2|^8.3|^8.4", 57 | "tomatophp/console-helpers": "^1.1", 58 | "filament/filament": "^4.0", 59 | "laravel/jetstream": "*", 60 | "laravel/sanctum": "*", 61 | "filament/spatie-laravel-media-library-plugin": "^4.0" 62 | }, 63 | "require-dev": { 64 | "larastan/larastan": "^2.9||^3.0", 65 | "laravel/pint": "^1.14", 66 | "nunomaduro/collision": "^8.1.1||^7.10.0", 67 | "orchestra/testbench": "^10.0.0||^9.0.0", 68 | "pestphp/pest": "^3.0", 69 | "pestphp/pest-plugin-arch": "^3.0", 70 | "pestphp/pest-plugin-laravel": "^3.0", 71 | "pestphp/pest-plugin-livewire": "^3.0", 72 | "pestphp/pest-plugin-type-coverage": "^3.5", 73 | "phpstan/extension-installer": "^1.3||^2.0", 74 | "phpstan/phpstan-deprecation-rules": "^1.1||^2.0", 75 | "phpstan/phpstan-phpunit": "^1.3||^2.0" 76 | }, 77 | "version": "v4.0.0" 78 | } 79 | -------------------------------------------------------------------------------- /src/Filament/Pages/Auth/LoginAccount.php: -------------------------------------------------------------------------------- 1 | trans('filament-saas-panel::messages.login.active'), 31 | ]); 32 | } 33 | 34 | public function authenticate(): ?LoginResponse 35 | { 36 | try { 37 | $this->rateLimit(5); 38 | } catch (TooManyRequestsException $exception) { 39 | Notification::make() 40 | ->title(trans('filament-saas-panel::messages.login.throttled.title', [ 41 | 'seconds' => $exception->secondsUntilAvailable, 42 | 'minutes' => ceil($exception->secondsUntilAvailable / 60), 43 | ])) 44 | ->body(trans('filament-saas-panel::messages.login.throttled.body', [ 45 | 'seconds' => $exception->secondsUntilAvailable, 46 | 'minutes' => ceil($exception->secondsUntilAvailable / 60), 47 | ])) 48 | ->danger() 49 | ->send(); 50 | 51 | return null; 52 | } 53 | 54 | $data = $this->form->getState(); 55 | 56 | if (! auth(config('filament-saas-panel.auth_guard'))->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)) { 57 | $this->throwFailureValidationException(); 58 | } 59 | 60 | $user = Filament::auth()->user(); 61 | 62 | if (! $user->is_active) { 63 | Filament::auth()->logout(); 64 | 65 | $this->throwFailureActivatedException(); 66 | } 67 | 68 | if ( 69 | ($user instanceof FilamentUser) && 70 | (! $user->canAccessPanel(Filament::getCurrentOrDefaultPanel())) 71 | ) { 72 | Filament::auth()->logout(); 73 | 74 | $this->throwFailureValidationException(); 75 | } 76 | 77 | session()->regenerate(); 78 | 79 | return app(LoginResponse::class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditProfile.php: -------------------------------------------------------------------------------- 1 | fillForms(); 68 | } 69 | 70 | protected function getForms(): array 71 | { 72 | return [ 73 | 'editProfileForm', 74 | 'editPasswordForm', 75 | 'deleteAccountForm', 76 | 'browserSessionsForm', 77 | ]; 78 | } 79 | 80 | protected function fillForms(): void 81 | { 82 | $data = $this->getUser()->attributesToArray(); 83 | 84 | $this->editProfileForm->fill($data); 85 | $this->editPasswordForm->fill(); 86 | } 87 | 88 | public function getUser() 89 | { 90 | return auth(config('filament-saas-panel.auth_guard'))->user(); 91 | } 92 | 93 | public function sendSuccessNotification() 94 | { 95 | Notification::make() 96 | ->title('Success') 97 | ->success() 98 | ->send(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Filament/Forms/DeleteAccountForm.php: -------------------------------------------------------------------------------- 1 | description(trans('filament-saas-panel::messages.profile.delete.delete_account_description')) 18 | ->schema([ 19 | Forms\Components\ViewField::make('deleteAccount') 20 | ->label(__('Delete Account')) 21 | ->hiddenLabel() 22 | ->view('filament-saas-panel::forms.components.delete-account-description'), 23 | Action::make('deleteAccount') 24 | ->label(trans('filament-saas-panel::messages.profile.delete.delete_account')) 25 | ->icon('heroicon-m-trash') 26 | ->color('danger') 27 | ->requiresConfirmation() 28 | ->modalHeading(trans('filament-saas-panel::messages.profile.delete.delete_account')) 29 | ->modalDescription(trans('filament-saas-panel::messages.profile.delete.are_you_sure')) 30 | ->modalSubmitActionLabel(trans('filament-saas-panel::messages.profile.delete.yes_delete_it')) 31 | ->schema([ 32 | Forms\Components\TextInput::make('password') 33 | ->password() 34 | ->revealable() 35 | ->label(trans('filament-saas-panel::messages.profile.delete.password')) 36 | ->required(), 37 | ]) 38 | ->action(function (array $data) { 39 | 40 | if (! Hash::check($data['password'], auth('accounts')->user()->password)) { 41 | self::sendErrorDeleteAccount(trans('filament-saas-panel::messages.profile.delete.incorrect_password')); 42 | 43 | return; 44 | } 45 | 46 | auth('accounts')->user()?->update([ 47 | 'is_active' => false, 48 | ]); 49 | 50 | auth('accounts')->user()?->delete(); 51 | }), 52 | ]), 53 | ]; 54 | } 55 | 56 | public static function sendErrorDeleteAccount(string $message): void 57 | { 58 | Notification::make() 59 | ->danger() 60 | ->title($message) 61 | ->send(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasManageRoles.php: -------------------------------------------------------------------------------- 1 | requiresConfirmation() 18 | ->link() 19 | ->color('info') 20 | ->label($role) 21 | ->modelLabel(trans('filament-saas-panel::messages.teams.members.manage_role')) 22 | ->schema(function (array $arguments) { 23 | return [ 24 | Select::make('role') 25 | ->default($arguments['role']) 26 | ->label(trans('filament-saas-panel::messages.teams.members.role')) 27 | ->searchable() 28 | ->preload() 29 | ->options(function () { 30 | $roles = collect(Jetstream::$roles)->transform(function ($role) { 31 | return with($role->jsonSerialize(), function ($data) { 32 | return (new Role( 33 | $data['key'], 34 | $data['name'], 35 | $data['permissions'] 36 | ))->description($data['description']); 37 | }); 38 | })->values(); 39 | 40 | return $roles->pluck('name', 'key'); 41 | }) 42 | ->rules(Jetstream::hasRoles() 43 | ? ['required', 'string', new \Laravel\Jetstream\Rules\Role] 44 | : null, ) 45 | ->validationMessages([ 46 | 'role.required' => trans('filament-saas-panel::messages.teams.members.role_required'), 47 | ]), 48 | ]; 49 | }) 50 | ->action(function (array $arguments, array $data) { 51 | $this->manageRole($arguments['user'], $data['role']); 52 | }); 53 | } 54 | 55 | public function manageRole(int $id, string $role) 56 | { 57 | try { 58 | Filament::getTenant()->users()->updateExistingPivot($id, [ 59 | 'role' => $role, 60 | ]); 61 | 62 | TeamMemberUpdated::dispatch(Filament::getTenant()->fresh(), Jetstream::findUserByIdOrFail($id)); 63 | } catch (Halt $exception) { 64 | return; 65 | } 66 | 67 | $this->sendSuccessNotification(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Actions/Jetstream/InviteTeamMember.php: -------------------------------------------------------------------------------- 1 | authorize('addTeamMember', $team); 26 | 27 | $this->validate($team, $email, $role); 28 | 29 | InvitingTeamMember::dispatch($team, $email, $role); 30 | 31 | $invitation = $team->teamInvitations()->create([ 32 | 'email' => $email, 33 | 'role' => $role, 34 | ]); 35 | 36 | $mail = config('filament-saas-panel.team_invitation_mail'); 37 | 38 | Mail::to($email)->send(new $mail($invitation)); 39 | } 40 | 41 | /** 42 | * Validate the invite member operation. 43 | */ 44 | protected function validate(Model $team, string $email, ?string $role): void 45 | { 46 | Validator::make([ 47 | 'email' => $email, 48 | 'role' => $role, 49 | ], $this->rules($team), [ 50 | 'email.unique' => __('This user has already been invited to the team.'), 51 | ])->after( 52 | $this->ensureUserIsNotAlreadyOnTeam($team, $email) 53 | )->validateWithBag('addTeamMember'); 54 | } 55 | 56 | /** 57 | * Get the validation rules for inviting a team member. 58 | */ 59 | protected function rules(Model $team): array 60 | { 61 | return array_filter([ 62 | 'email' => [ 63 | 'required', 'email', 64 | Rule::unique('team_invitations')->where(function (Builder $query) use ($team) { 65 | $query->where('team_id', $team->id); 66 | }), 67 | ], 68 | 'role' => Jetstream::hasRoles() 69 | ? ['required', 'string', new Role] 70 | : null, 71 | ]); 72 | } 73 | 74 | /** 75 | * Ensure that the user is not already on the team. 76 | */ 77 | protected function ensureUserIsNotAlreadyOnTeam(Model $team, string $email): Closure 78 | { 79 | return function ($validator) use ($team, $email) { 80 | $validator->errors()->addIf( 81 | $team->hasUserWithEmail($email), 82 | 'email', 83 | __('This user already belongs to the team.') 84 | ); 85 | }; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /resources/views/forms/components/browser-sessions.blade.php: -------------------------------------------------------------------------------- 1 | 5 |
6 |
7 |
8 |
9 | {{ trans('filament-saas-panel::messages.profile.browser.sessions_content') }} 10 |
11 | @if (count($data) > 0) 12 |
13 | @foreach ($data as $session) 14 |
15 |
16 | @if ($session->device['desktop']) 17 | 21 | @else 22 | 26 | @endif 27 |
28 | 29 |
30 |
31 | {{ $session->device['platform'] ? $session->device['platform'] : __('Unknown') }} - {{ $session->device['browser'] ? $session->device['browser'] : __('Unknown') }} 32 |
33 | 34 |
35 |
36 | {{ $session->ip_address }}, 37 | 38 | @if ($session->is_current_device) 39 | {{ trans('filament-saas-panel::messages.profile.browser.sessions_device') }} 40 | @else 41 | {{ trans('filament-saas-panel::messages.profile.browser.sessions_last_active') }} {{ $session->last_active }} 42 | @endif 43 |
44 |
45 |
46 |
47 | @endforeach 48 |
49 | @endif 50 | 51 |
52 |
53 |
54 |
55 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skills, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /src/Filament/Forms/DeleteTeamForm.php: -------------------------------------------------------------------------------- 1 | description(trans('filament-saas-panel::messages.profile.delete-team.description')) 20 | ->schema([ 21 | Forms\Components\ViewField::make('deleteTeam') 22 | ->label(__('Delete Team')) 23 | ->hiddenLabel() 24 | ->view('filament-saas-panel::forms.components.delete-team-description'), 25 | Action::make('deleteAccount') 26 | ->label(trans('filament-saas-panel::messages.profile.delete-team.delete')) 27 | ->icon('heroicon-m-trash') 28 | ->color('danger') 29 | ->requiresConfirmation() 30 | ->modalHeading(trans('filament-saas-panel::messages.profile.delete-team.delete_account')) 31 | ->modalDescription(trans('filament-saas-panel::messages.profile.delete-team.are_you_sure')) 32 | ->modalSubmitActionLabel(trans('filament-saas-panel::messages.profile.delete-team.yes_delete_it')) 33 | ->schema([ 34 | Forms\Components\TextInput::make('password') 35 | ->password() 36 | ->revealable() 37 | ->label(trans('filament-saas-panel::messages.profile.delete-team.password')) 38 | ->required(), 39 | ]) 40 | ->action(function (array $data) use ($team) { 41 | 42 | if (! Hash::check($data['password'], Auth::user()->password)) { 43 | self::sendErrorDeleteAccount(trans('filament-saas-panel::messages.profile.delete-team.incorrect_password')); 44 | 45 | return; 46 | } 47 | 48 | $team?->delete(); 49 | 50 | Notification::make() 51 | ->title('Team deleted') 52 | ->body('The team has been deleted successfully.') 53 | ->success() 54 | ->send(); 55 | 56 | return redirect()->to(url(Filament::getCurrentPanel()->getId())); 57 | }), 58 | ]), 59 | ]; 60 | } 61 | 62 | public static function sendErrorDeleteAccount(string $message): void 63 | { 64 | Notification::make() 65 | ->danger() 66 | ->title($message) 67 | ->send(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Filament/Pages/Auth/RegisterAccountWithoutOTP.php: -------------------------------------------------------------------------------- 1 | 32 | */ 33 | protected function getForms(): array 34 | { 35 | return [ 36 | 'form' => $this->form( 37 | $this->makeForm() 38 | ->schema([ 39 | $this->getNameFormComponent(), 40 | $this->getEmailFormComponent(), 41 | TextInput::make('phone')->label('Phone')->required()->unique(), 42 | TextInput::make('username')->label('Username')->required()->unique(), 43 | Hidden::make('loginBy')->default('email'), 44 | $this->getPasswordFormComponent(), 45 | $this->getPasswordConfirmationFormComponent(), 46 | ]) 47 | ->statePath('data'), 48 | ), 49 | ]; 50 | } 51 | 52 | public function register(): ?RegistrationResponse 53 | { 54 | try { 55 | $this->rateLimit(2); 56 | } catch (TooManyRequestsException $exception) { 57 | Notification::make() 58 | ->title(__('filament-panels::pages/auth/register.notifications.throttled.title', [ 59 | 'seconds' => $exception->secondsUntilAvailable, 60 | 'minutes' => ceil($exception->secondsUntilAvailable / 60), 61 | ])) 62 | ->body(array_key_exists('body', __('filament-panels::pages/auth/register.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/register.notifications.throttled.body', [ 63 | 'seconds' => $exception->secondsUntilAvailable, 64 | 'minutes' => ceil($exception->secondsUntilAvailable / 60), 65 | ]) : null) 66 | ->danger() 67 | ->send(); 68 | 69 | return null; 70 | } 71 | 72 | $user = DB::transaction(function () { 73 | $data = $this->form->getState(); 74 | 75 | return config('filament-saas-panel.user_model')::create($data); 76 | }); 77 | 78 | event(new Registered($user)); 79 | 80 | $user->is_active = true; 81 | $user->save(); 82 | 83 | Filament::auth()->login($user); 84 | 85 | session()->regenerate(); 86 | 87 | return app(RegistrationResponse::class); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Filament/Pages/Auth/RegisterAccount.php: -------------------------------------------------------------------------------- 1 | 33 | */ 34 | protected function getForms(): array 35 | { 36 | return [ 37 | 'form' => $this->form( 38 | $this->makeForm() 39 | ->schema([ 40 | $this->getNameFormComponent(), 41 | $this->getEmailFormComponent(), 42 | TextInput::make('phone')->label('Phone')->required()->unique(), 43 | TextInput::make('username')->label('Username')->required()->unique(), 44 | Hidden::make('loginBy')->default('email'), 45 | $this->getPasswordFormComponent(), 46 | $this->getPasswordConfirmationFormComponent(), 47 | ]) 48 | ->statePath('data'), 49 | ), 50 | ]; 51 | } 52 | 53 | public function register(): ?RegistrationResponse 54 | { 55 | try { 56 | $this->rateLimit(2); 57 | } catch (TooManyRequestsException $exception) { 58 | Notification::make() 59 | ->title(__('filament-panels::pages/auth/register.notifications.throttled.title', [ 60 | 'seconds' => $exception->secondsUntilAvailable, 61 | 'minutes' => ceil($exception->secondsUntilAvailable / 60), 62 | ])) 63 | ->body(array_key_exists('body', __('filament-panels::pages/auth/register.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/register.notifications.throttled.body', [ 64 | 'seconds' => $exception->secondsUntilAvailable, 65 | 'minutes' => ceil($exception->secondsUntilAvailable / 60), 66 | ]) : null) 67 | ->danger() 68 | ->send(); 69 | 70 | return null; 71 | } 72 | 73 | $user = DB::transaction(function () { 74 | $data = $this->form->getState(); 75 | 76 | return $this->getUserModel()::create($data); 77 | }); 78 | 79 | event(new Registered($user)); 80 | 81 | $user->otp_code = substr(number_format(time() * rand(), 0, '', ''), 0, 6); 82 | $user->save(); 83 | 84 | event(new SendOTP(config('filament-saas-panel.user_model'), $user->id)); 85 | 86 | session()->put('user_email', $user->email); 87 | 88 | return app(RegisterResponse::class); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Filament/Forms/ManageTeamMembersForm.php: -------------------------------------------------------------------------------- 1 | label(trans('filament-saas-panel::messages.teams.members.title')) 21 | ->hiddenLabel() 22 | ->view('filament-saas-panel::forms.components.team-members', ['team' => $team]), 23 | TextInput::make('email')->label('Email') 24 | ->label(trans('filament-saas-panel::messages.teams.members.email')) 25 | ->rules([ 26 | 'required', 27 | 'email', 28 | 'not_in:'.$team->owner->email, 29 | Rule::unique('team_invitations', 'email') 30 | ->where(function (Builder $query) use ($team) { 31 | $query->where('team_id', $team->id); 32 | }), 33 | ]) 34 | ->validationMessages([ 35 | 'email.not_in' => trans('filament-saas-panel::messages.teams.members.not_in'), 36 | 'email.required' => trans('filament-saas-panel::messages.teams.members.required'), 37 | 'email.unique' => trans('filament-saas-panel::messages.teams.members.unique'), 38 | ]) 39 | ->disabled(fn () => auth(config('filament-saas-panel.auth_guard'))->user()->id !== $team->{config('filament-saas-panel.team_id_column')}), 40 | Forms\Components\Select::make('role') 41 | ->label(trans('filament-saas-panel::messages.teams.members.role')) 42 | ->searchable() 43 | ->preload() 44 | ->options(function () { 45 | $roles = collect(Jetstream::$roles)->transform(function ($role) { 46 | return (new Role( 47 | $role->key, 48 | $role->name, 49 | $role->permissions 50 | ))->description($role->description); 51 | })->values(); 52 | 53 | return $roles->pluck('name', 'key'); 54 | }) 55 | ->rules(Jetstream::hasRoles() 56 | ? ['required', 'string', new \Laravel\Jetstream\Rules\Role] 57 | : null, ) 58 | ->validationMessages([ 59 | 'role.required' => trans('filament-saas-panel::messages.teams.members.role_required'), 60 | ]) 61 | ->disabled(fn () => auth(config('filament-saas-panel.auth_guard'))->user()->id !== $team->{config('filament-saas-panel.team_id_column')}), 62 | Action::make('sendInvitation') 63 | ->label(trans('filament-saas-panel::messages.teams.members.send_invitation')) 64 | ->submit('manageTeamMembersForm') 65 | ->color('primary'), 66 | ]; 67 | } 68 | 69 | public static function sendErrorDeleteAccount(string $message): void 70 | { 71 | Notification::make() 72 | ->danger() 73 | ->title($message) 74 | ->send(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /tests/src/TestCase.php: -------------------------------------------------------------------------------- 1 | panel = Filament::getCurrentOrDefaultPanel(); 46 | 47 | Jetstream::useUserModel(config('filament-saas-panel.user_model')); 48 | Jetstream::useTeamModel(config('filament-saas-panel.team_model')); 49 | Jetstream::useMembershipModel(config('filament-saas-panel.membership_model')); 50 | Jetstream::useTeamInvitationModel(config('filament-saas-panel.team_invitation_model')); 51 | } 52 | 53 | protected function getPackageProviders($app): array 54 | { 55 | $providers = [ 56 | ActionsServiceProvider::class, 57 | BladeCaptureDirectiveServiceProvider::class, 58 | BladeHeroiconsServiceProvider::class, 59 | BladeIconsServiceProvider::class, 60 | FilamentServiceProvider::class, 61 | FormsServiceProvider::class, 62 | InfolistsServiceProvider::class, 63 | LivewireServiceProvider::class, 64 | NotificationsServiceProvider::class, 65 | SupportServiceProvider::class, 66 | SchemasServiceProvider::class, 67 | TablesServiceProvider::class, 68 | WidgetsServiceProvider::class, 69 | MediaLibraryServiceProvider::class, 70 | JetstreamServiceProvider::class, 71 | FortifyServiceProvider::class, 72 | FilamentSaasPanelServiceProvider::class, 73 | AppPanelProvider::class, 74 | AdminPanelProvider::class, 75 | ]; 76 | 77 | sort($providers); 78 | 79 | return $providers; 80 | } 81 | 82 | protected function defineDatabaseMigrations(): void 83 | { 84 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); 85 | } 86 | 87 | public function getEnvironmentSetUp($app): void 88 | { 89 | $app['config']->set('database.default', 'testing'); 90 | $app['config']->set('auth.guards.testing.driver', 'session'); 91 | $app['config']->set('auth.guards.testing.provider', 'testing'); 92 | $app['config']->set('auth.providers.testing.driver', 'eloquent'); 93 | $app['config']->set('auth.providers.testing.model', User::class); 94 | $app['config']->set('filament-saas-panel.user_model', User::class); 95 | $app['config']->set('filament-saas-panel.team_model', Team::class); 96 | $app['config']->set('filament-saas-panel.membership_model', Membership::class); 97 | $app['config']->set('filament-saas-panel.team_invitation_model', TeamInvitation::class); 98 | 99 | $app['config']->set('view.paths', [ 100 | ...$app['config']->get('view.paths'), 101 | __DIR__.'/../resources/views', 102 | ]); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /database/migrations/2025_08_25_143941_add_otp_fields_if_not_exists_table.php: -------------------------------------------------------------------------------- 1 | string('phone')->nullable(); 20 | } 21 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'username')) { 22 | $table->string('username')->nullable(); 23 | } 24 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'login_by')) { 25 | $table->string('login_by')->nullable(); 26 | } 27 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_code')) { 28 | $table->string('otp_code')->nullable(); 29 | } 30 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_activated_at')) { 31 | $table->dateTime('otp_activated_at')->nullable(); 32 | } 33 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'last_login')) { 34 | $table->dateTime('last_login')->nullable(); 35 | } 36 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'agent')) { 37 | $table->longText('agent')->nullable(); 38 | } 39 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'host')) { 40 | $table->string('host')->nullable(); 41 | } 42 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_login')) { 43 | $table->boolean('is_login')->default(0)->nullable(); 44 | } 45 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_active')) { 46 | $table->boolean('is_active')->default(false); 47 | } 48 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_notification_active')) { 49 | $table->boolean('is_notification_active')->default(true); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | public function down() 56 | { 57 | Schema::table(config('filament-saas-panel.user_table'), function (Blueprint $table) { 58 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'phone')) { 59 | $table->dropColumn('phone'); 60 | } 61 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'username')) { 62 | $table->dropColumn('username'); 63 | } 64 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'login_by')) { 65 | $table->dropColumn('login_by'); 66 | } 67 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_code')) { 68 | $table->dropColumn('otp_code'); 69 | } 70 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_activated_at')) { 71 | $table->dropColumn('otp_activated_at'); 72 | } 73 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'last_login')) { 74 | $table->dropColumn('last_login'); 75 | } 76 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'agent')) { 77 | $table->dropColumn('agent'); 78 | } 79 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'host')) { 80 | $table->dropColumn('host'); 81 | } 82 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_login')) { 83 | $table->dropColumn('is_login'); 84 | } 85 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_active')) { 86 | $table->dropColumn('is_active'); 87 | } 88 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_notification_active')) { 89 | $table->dropColumn('is_notification_active'); 90 | } 91 | }); 92 | } 93 | }; 94 | -------------------------------------------------------------------------------- /tests/database/migrations/2025_08_25_143941_add_otp_fields_if_not_exists_table.php: -------------------------------------------------------------------------------- 1 | string('phone')->nullable(); 20 | } 21 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'username')) { 22 | $table->string('username')->nullable(); 23 | } 24 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'login_by')) { 25 | $table->string('login_by')->nullable(); 26 | } 27 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_code')) { 28 | $table->string('otp_code')->nullable(); 29 | } 30 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_activated_at')) { 31 | $table->dateTime('otp_activated_at')->nullable(); 32 | } 33 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'last_login')) { 34 | $table->dateTime('last_login')->nullable(); 35 | } 36 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'agent')) { 37 | $table->longText('agent')->nullable(); 38 | } 39 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'host')) { 40 | $table->string('host')->nullable(); 41 | } 42 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_login')) { 43 | $table->boolean('is_login')->default(0)->nullable(); 44 | } 45 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_active')) { 46 | $table->boolean('is_active')->default(false); 47 | } 48 | if (! Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_notification_active')) { 49 | $table->boolean('is_notification_active')->default(true); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | public function down() 56 | { 57 | Schema::table(config('filament-saas-panel.user_table'), function (Blueprint $table) { 58 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'phone')) { 59 | $table->dropColumn('phone'); 60 | } 61 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'username')) { 62 | $table->dropColumn('username'); 63 | } 64 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'login_by')) { 65 | $table->dropColumn('login_by'); 66 | } 67 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_code')) { 68 | $table->dropColumn('otp_code'); 69 | } 70 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'otp_activated_at')) { 71 | $table->dropColumn('otp_activated_at'); 72 | } 73 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'last_login')) { 74 | $table->dropColumn('last_login'); 75 | } 76 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'agent')) { 77 | $table->dropColumn('agent'); 78 | } 79 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'host')) { 80 | $table->dropColumn('host'); 81 | } 82 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_login')) { 83 | $table->dropColumn('is_login'); 84 | } 85 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_active')) { 86 | $table->dropColumn('is_active'); 87 | } 88 | if (Schema::hasColumn(config('filament-saas-panel.user_table'), 'is_notification_active')) { 89 | $table->dropColumn('is_notification_active'); 90 | } 91 | }); 92 | } 93 | }; 94 | -------------------------------------------------------------------------------- /src/Filament/Pages/EditTeam/HasTeamInvitation.php: -------------------------------------------------------------------------------- 1 | requiresConfirmation() 20 | ->color('warning') 21 | ->label(trans('filament-saas-panel::messages.teams.actions.resend_invitation')) 22 | ->action(function (array $arguments) { 23 | $this->resendTeamInvitation($arguments['invitation']); 24 | }); 25 | } 26 | 27 | public function resendTeamInvitation($invitationId) 28 | { 29 | try { 30 | $model = Jetstream::teamInvitationModel(); 31 | 32 | $invitation = $model::whereKey($invitationId)->first(); 33 | 34 | $mail = config('filament-saas-panel.team_invitation_mail'); 35 | 36 | Mail::to($invitation->email)->send(new $mail($invitation)); 37 | 38 | $account = config('filament-saas-panel.user_model')::where('email', $invitation->email)->first(); 39 | 40 | if ($account) { 41 | Notification::make() 42 | ->title(trans('filament-saas-panel::messages.teams.members.notifications.title')) 43 | ->body(trans('filament-saas-panel::messages.teams.members.notifications.body', ['team' => $invitation->team->name])) 44 | ->success() 45 | ->actions([ 46 | Action::make('acceptInvitation') 47 | ->label(trans('filament-saas-panel::messages.teams.members.notifications.accept')) 48 | ->color('success') 49 | ->markAsRead() 50 | ->url(route('team-invitations.accept', ['invitation' => $invitation->id])), 51 | Action::make('cancelInvitation') 52 | ->label(trans('filament-saas-panel::messages.teams.members.notifications.cancel')) 53 | ->color('danger') 54 | ->url(route('team-invitations.cancel', ['invitation' => $invitation->id])), 55 | ]) 56 | ->sendToDatabase($account); 57 | } 58 | } catch (Halt $exception) { 59 | return; 60 | } 61 | 62 | $this->sendSuccessNotification(); 63 | } 64 | 65 | public function sendInvitation() 66 | { 67 | try { 68 | $data = $this->manageTeamMembersForm->getState(); 69 | $this->manageTeamInvitations(Filament::getTenant(), $data); 70 | } catch (Halt $exception) { 71 | return; 72 | } 73 | 74 | $this->sendSuccessNotification(); 75 | } 76 | 77 | protected function manageTeamInvitations(Model $record, array $data) 78 | { 79 | $user = auth(config('filament-saas-panel.auth_guard'))->user(); 80 | $team = $record; 81 | $email = $data['email']; 82 | $role = $data['role']; 83 | 84 | InvitingTeamMember::dispatch($team, $email, $role); 85 | 86 | $invitation = $team->teamInvitations()->create([ 87 | 'email' => $email, 88 | 'role' => $role, 89 | ]); 90 | 91 | $mail = config('filament-saas-panel.team_invitation_mail'); 92 | 93 | Mail::to($email)->send(new $mail($invitation)); 94 | 95 | $account = config('filament-saas-panel.user_model')::where('email', $email)->first(); 96 | 97 | if ($account) { 98 | Notification::make() 99 | ->title(trans('filament-saas-panel::messages.teams.members.notifications.title')) 100 | ->body(trans('filament-saas-panel::messages.teams.members.notifications.body', ['team' => $team->name])) 101 | ->success() 102 | ->actions([ 103 | Action::make('acceptInvitation') 104 | ->label(trans('filament-saas-panel::messages.teams.members.notifications.accept')) 105 | ->color('success') 106 | ->markAsRead() 107 | ->url(route('accounts.team-invitations.accept', ['invitation' => $invitation->id])), 108 | Action::make('cancelInvitation') 109 | ->label(trans('filament-saas-panel::messages.teams.members.notifications.cancel')) 110 | ->color('danger') 111 | ->url(route('accounts.team-invitations.cancel', ['invitation' => $invitation->id])), 112 | ]) 113 | ->sendToDatabase($account); 114 | } 115 | 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Filament/Resources/TeamResource.php: -------------------------------------------------------------------------------- 1 | schema([ 49 | Forms\Components\SpatieMediaLibraryFileUpload::make('avatar') 50 | ->label(trans('filament-accounts::messages.team.columns.avatar')) 51 | ->hiddenLabel() 52 | ->alignCenter() 53 | ->avatar() 54 | ->collection('avatar') 55 | ->image(), 56 | Forms\Components\TextInput::make('name') 57 | ->label(trans('filament-accounts::messages.team.columns.name')) 58 | ->required() 59 | ->maxLength(255), 60 | Forms\Components\Select::make('account_id') 61 | ->label(trans('filament-accounts::messages.team.columns.owner')) 62 | ->relationship('owner', 'name') 63 | ->preload() 64 | ->searchable(), 65 | Forms\Components\Toggle::make('personal_team') 66 | ->label(trans('filament-accounts::messages.team.columns.personal_team')), 67 | ])->columns(1); 68 | } 69 | 70 | public static function table(Table $table): Table 71 | { 72 | return $table 73 | ->columns([ 74 | Tables\Columns\TextColumn::make('owner.name') 75 | ->label(trans('filament-accounts::messages.team.columns.owner')) 76 | ->sortable(), 77 | Tables\Columns\ImageColumn::make('avatar') 78 | ->circular() 79 | ->label(trans('filament-accounts::messages.team.columns.avatar')) 80 | ->toggleable(), 81 | Tables\Columns\TextColumn::make('name') 82 | ->label(trans('filament-accounts::messages.team.columns.name')) 83 | ->searchable() 84 | ->sortable(), 85 | Tables\Columns\IconColumn::make('personal_team') 86 | ->label(trans('filament-accounts::messages.team.columns.personal_team')) 87 | ->toggleable(isToggledHiddenByDefault: true), 88 | Tables\Columns\TextColumn::make('created_at') 89 | ->dateTime() 90 | ->sortable() 91 | ->toggleable(isToggledHiddenByDefault: true), 92 | Tables\Columns\TextColumn::make('updated_at') 93 | ->dateTime() 94 | ->sortable() 95 | ->toggleable(isToggledHiddenByDefault: true), 96 | ]) 97 | ->filters([ 98 | Tables\Filters\SelectFilter::make('owner') 99 | ->label(trans('filament-accounts::messages.team.columns.owner')) 100 | ->searchable() 101 | ->relationship('owner', 'name'), 102 | ]) 103 | ->recordActions([ 104 | EditAction::make(), 105 | DeleteAction::make(), 106 | ]) 107 | ->defaultSort('id', 'desc') 108 | ->toolbarActions([ 109 | BulkActionGroup::make([ 110 | DeleteBulkAction::make(), 111 | ]), 112 | ]); 113 | } 114 | 115 | public static function getRelations(): array 116 | { 117 | return [ 118 | // 119 | ]; 120 | } 121 | 122 | public static function getPages(): array 123 | { 124 | return [ 125 | 'index' => \TomatoPHP\FilamentSaasPanel\Filament\Resources\TeamResource\Pages\ListTeams::route('/'), 126 | ]; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /tests/src/PluginTest.php: -------------------------------------------------------------------------------- 1 | plugins([ 10 | FilamentSaasPanelPlugin::make(), 11 | ]); 12 | 13 | expect($panel->getPlugin('filament-saas-panel')) 14 | ->not() 15 | ->toThrow(Exception::class); 16 | }); 17 | 18 | it('can modify profile menu', function ($condition) { 19 | $plugin = FilamentSaasPanelPlugin::make() 20 | ->editProfileMenu($condition); 21 | 22 | expect($plugin->editProfileMenu)->toBe($condition); 23 | })->with([ 24 | false, 25 | fn () => true, 26 | ]); 27 | 28 | it('can modify team slug', function ($condition) { 29 | $plugin = FilamentSaasPanelPlugin::make() 30 | ->teamSlug($condition); 31 | 32 | expect($plugin->teamSlug)->toBe($condition); 33 | })->with([ 34 | 'slug', 35 | fn () => 'slug', 36 | ]); 37 | 38 | it('can modify API Token Manager', function ($condition) { 39 | $plugin = FilamentSaasPanelPlugin::make() 40 | ->APITokenManager($condition); 41 | 42 | expect($plugin->APITokenManager)->toBe($condition); 43 | })->with([ 44 | false, 45 | fn () => true, 46 | ]); 47 | 48 | it('can modify Edit team', function ($condition) { 49 | $plugin = FilamentSaasPanelPlugin::make() 50 | ->editTeam($condition); 51 | 52 | expect($plugin->editTeam)->toBe($condition); 53 | })->with([ 54 | false, 55 | fn () => true, 56 | ]); 57 | 58 | it('can modify Edit profile', function ($condition) { 59 | $plugin = FilamentSaasPanelPlugin::make() 60 | ->editProfile($condition); 61 | 62 | expect($plugin->editProfile)->toBe($condition); 63 | })->with([ 64 | false, 65 | fn () => true, 66 | ]); 67 | 68 | it('can modify Edit password', function ($condition) { 69 | $plugin = FilamentSaasPanelPlugin::make() 70 | ->editPassword($condition); 71 | 72 | expect($plugin->editPassword)->toBe($condition); 73 | })->with([ 74 | false, 75 | fn () => true, 76 | ]); 77 | 78 | it('can modify delete account', function ($condition) { 79 | $plugin = FilamentSaasPanelPlugin::make() 80 | ->deleteAccount($condition); 81 | 82 | expect($plugin->deleteAccount)->toBe($condition); 83 | })->with([ 84 | false, 85 | fn () => true, 86 | ]); 87 | 88 | it('can modify browser session manager', function ($condition) { 89 | $plugin = FilamentSaasPanelPlugin::make() 90 | ->browserSessionManager($condition); 91 | 92 | expect($plugin->browserSessionManager)->toBe($condition); 93 | })->with([ 94 | false, 95 | fn () => true, 96 | ]); 97 | 98 | it('can modify registration', function ($condition) { 99 | $plugin = FilamentSaasPanelPlugin::make() 100 | ->registration($condition); 101 | 102 | expect($plugin->registration)->toBe($condition); 103 | })->with([ 104 | false, 105 | fn () => true, 106 | ]); 107 | 108 | it('can modify use Jetstream Team Model', function ($condition) { 109 | $plugin = FilamentSaasPanelPlugin::make() 110 | ->useJetstreamTeamModel($condition); 111 | 112 | expect($plugin->useJetstreamTeamModel)->toBe($condition); 113 | })->with([ 114 | false, 115 | fn () => true, 116 | ]); 117 | 118 | it('can modify team Invitation', function ($condition) { 119 | $plugin = FilamentSaasPanelPlugin::make() 120 | ->teamInvitation($condition); 121 | 122 | expect($plugin->teamInvitation)->toBe($condition); 123 | })->with([ 124 | false, 125 | fn () => true, 126 | ]); 127 | 128 | it('can modify delete Team', function ($condition) { 129 | $plugin = FilamentSaasPanelPlugin::make() 130 | ->deleteTeam($condition); 131 | 132 | expect($plugin->deleteTeam)->toBe($condition); 133 | })->with([ 134 | false, 135 | fn () => true, 136 | ]); 137 | 138 | it('can modify allow tenants', function ($condition) { 139 | $plugin = FilamentSaasPanelPlugin::make() 140 | ->allowTenants($condition); 141 | 142 | expect($plugin->allowTenants)->toBe($condition); 143 | })->with([ 144 | false, 145 | fn () => true, 146 | ]); 147 | 148 | it('can modify show Team Members', function ($condition) { 149 | $plugin = FilamentSaasPanelPlugin::make() 150 | ->showTeamMembers($condition); 151 | 152 | expect($plugin->showTeamMembers)->toBe($condition); 153 | })->with([ 154 | false, 155 | fn () => true, 156 | ]); 157 | 158 | it('can modify check Account Status In Login', function ($condition) { 159 | $plugin = FilamentSaasPanelPlugin::make() 160 | ->checkAccountStatusInLogin($condition); 161 | 162 | expect($plugin->checkAccountStatusInLogin)->toBe($condition); 163 | })->with([ 164 | false, 165 | fn () => true, 166 | ]); 167 | 168 | it('can modify use OTP Activation', function ($condition) { 169 | $plugin = FilamentSaasPanelPlugin::make() 170 | ->useOTPActivation($condition); 171 | 172 | expect($plugin->useOTPActivation)->toBe($condition); 173 | })->with([ 174 | false, 175 | fn () => true, 176 | ]); 177 | -------------------------------------------------------------------------------- /src/Filament/Forms/BrowserSessionsForm.php: -------------------------------------------------------------------------------- 1 | description(trans('filament-saas-panel::messages.profile.browser.browser_section_description')) 22 | ->schema([ 23 | Forms\Components\ViewField::make('browserSessions') 24 | ->label(__(trans('filament-saas-panel::messages.profile.browser.browser_section_title'))) 25 | ->hiddenLabel() 26 | ->view('filament-saas-panel::forms.components.browser-sessions') 27 | ->viewData(['data' => self::getSessions()]), 28 | Action::make('deleteBrowserSessions') 29 | ->label(trans('filament-saas-panel::messages.profile.browser.browser_sessions_log_out')) 30 | ->requiresConfirmation() 31 | ->modalHeading(trans('filament-saas-panel::messages.profile.browser.browser_sessions_log_out')) 32 | ->modalDescription(trans('filament-saas-panel::messages.profile.browser.browser_sessions_confirm_pass')) 33 | ->modalSubmitActionLabel(trans('filament-saas-panel::messages.profile.browser.browser_sessions_log_out')) 34 | ->schema([ 35 | Forms\Components\TextInput::make('password') 36 | ->password() 37 | ->revealable() 38 | ->label(trans('filament-saas-panel::messages.profile.browser.password')) 39 | ->required(), 40 | ]) 41 | ->action(function (array $data) { 42 | self::logoutOtherBrowserSessions($data['password']); 43 | 44 | Notification::make() 45 | ->title('Success') 46 | ->success() 47 | ->send(); 48 | }) 49 | ->modalWidth('2xl'), 50 | 51 | ]), 52 | ]; 53 | } 54 | 55 | public static function getSessions(): array 56 | { 57 | if (config(key: 'session.driver') !== 'database') { 58 | return []; 59 | } 60 | 61 | return collect( 62 | value: DB::connection(config(key: 'session.connection'))->table(table: config(key: 'session.table', default: 'sessions')) 63 | ->where(column: 'user_id', operator: Auth::user()->getAuthIdentifier()) 64 | ->latest(column: 'last_activity') 65 | ->get() 66 | )->map(callback: function ($session): object { 67 | $agent = self::createAgent($session); 68 | 69 | return (object) [ 70 | 'device' => [ 71 | 'browser' => $agent->browser(), 72 | 'desktop' => $agent->isDesktop(), 73 | 'mobile' => $agent->isMobile(), 74 | 'tablet' => $agent->isTablet(), 75 | 'platform' => $agent->platform(), 76 | ], 77 | 'ip_address' => $session->ip_address, 78 | 'is_current_device' => $session->id === request()->session()->getId(), 79 | 'last_active' => Carbon::createFromTimestamp($session->last_activity)->diffForHumans(), 80 | ]; 81 | })->toArray(); 82 | } 83 | 84 | protected static function createAgent(mixed $session) 85 | { 86 | return tap( 87 | value: new Agent, 88 | callback: fn ($agent) => $agent->setUserAgent(userAgent: $session->user_agent) 89 | ); 90 | } 91 | 92 | public static function logoutOtherBrowserSessions($password): void 93 | { 94 | 95 | if (! Hash::check($password, Auth::user()->password)) { 96 | Notification::make() 97 | ->danger() 98 | ->title(trans('filament-saas-panel::messages.profile.browser.incorrect_password')) 99 | ->send(); 100 | 101 | return; 102 | } 103 | 104 | Auth::guard()->logoutOtherDevices($password); 105 | 106 | request()->session()->put([ 107 | 'password_hash_'.Auth::getDefaultDriver() => Auth::user()->getAuthPassword(), 108 | ]); 109 | 110 | self::deleteOtherSessionRecords(); 111 | } 112 | 113 | protected static function deleteOtherSessionRecords() 114 | { 115 | if (config('session.driver') !== 'database') { 116 | return; 117 | } 118 | 119 | DB::connection(config('session.connection'))->table(config('session.table', 'sessions')) 120 | ->where('user_id', Auth::user()->getAuthIdentifier()) 121 | ->where('id', '!=', request()->session()->getId()) 122 | ->delete(); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | . 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /config/filament-saas-panel.php: -------------------------------------------------------------------------------- 1 | 'app', 12 | 13 | /** 14 | * -------------------------------------------------------------- 15 | * Panel Pages 16 | * -------------------------------------------------------------- 17 | * 18 | * This is where you can define the pages that will be used in the panel. 19 | */ 20 | 'pages' => [ 21 | 'teams' => [ 22 | 'create' => \TomatoPHP\FilamentSaasPanel\Filament\Pages\CreateTeam::class, 23 | 'edit' => \TomatoPHP\FilamentSaasPanel\Filament\Pages\EditTeam::class, 24 | ], 25 | 'profile' => [ 26 | 'edit' => \TomatoPHP\FilamentSaasPanel\Filament\Pages\EditProfile::class, 27 | ], 28 | 'auth' => [ 29 | 'login' => \TomatoPHP\FilamentSaasPanel\Filament\Pages\Auth\LoginAccount::class, 30 | 'register' => \TomatoPHP\FilamentSaasPanel\Filament\Pages\Auth\RegisterAccount::class, 31 | 'register-without-otp' => \TomatoPHP\FilamentSaasPanel\Filament\Pages\Auth\RegisterAccountWithoutOTP::class, 32 | ], 33 | ], 34 | 35 | /** 36 | * -------------------------------------------------------------- 37 | * Auth Guard 38 | * -------------------------------------------------------------- 39 | * 40 | * This is the guard that will be used to authenticate the user. 41 | */ 42 | 'auth_guard' => 'web', 43 | 44 | /** 45 | * -------------------------------------------------------------- 46 | * User Model 47 | * -------------------------------------------------------------- 48 | * 49 | * This is the model that will be used to interact with the user. 50 | */ 51 | 'user_model' => \App\Models\User::class, 52 | 53 | /** 54 | * -------------------------------------------------------------- 55 | * User Table 56 | * -------------------------------------------------------------- 57 | * 58 | * This is the table that will be used to interact with the user. 59 | */ 60 | 'user_table' => 'users', 61 | 62 | /** 63 | * -------------------------------------------------------------- 64 | * Team Model 65 | * -------------------------------------------------------------- 66 | * 67 | * This is the model that will be used to interact with the team. 68 | */ 69 | 'team_model' => \App\Models\Team::class, 70 | 71 | /** 72 | * -------------------------------------------------------------- 73 | * Team ID Column 74 | * -------------------------------------------------------------- 75 | * 76 | * This is the column that will be used to identify the team owner. 77 | */ 78 | 'team_id_column' => 'user_id', 79 | 80 | /** 81 | * -------------------------------------------------------------- 82 | * Team Invitation Model 83 | * -------------------------------------------------------------- 84 | * 85 | * This is the model that will be used to interact with the team invitation. 86 | */ 87 | 'team_invitation_model' => \App\Models\TeamInvitation::class, 88 | 89 | /** 90 | * -------------------------------------------------------------- 91 | * Membership Model 92 | * -------------------------------------------------------------- 93 | * 94 | * This is the model that will be used to interact with the membership. 95 | */ 96 | 'membership_model' => \App\Models\Membership::class, 97 | 98 | /** 99 | * -------------------------------------------------------------- 100 | * Registration URL 101 | * -------------------------------------------------------------- 102 | * 103 | * This is the URL that will be used to register a new user. 104 | */ 105 | 'registration_url' => 'register', 106 | 107 | /** 108 | * -------------------------------------------------------------- 109 | * Registration URL 110 | * -------------------------------------------------------------- 111 | * 112 | * This is the URL that will be used to register a new user. 113 | */ 114 | 'login_url' => 'login', 115 | 116 | /** 117 | * -------------------------------------------------------------- 118 | * Team Invitation Mail 119 | * -------------------------------------------------------------- 120 | * 121 | * This is the mail that will be used to send the team invitation. 122 | */ 123 | 'team_invitation_mail' => \TomatoPHP\FilamentSaasPanel\Mail\TeamInvitation::class, 124 | 125 | /** 126 | * -------------------------------------------------------------- 127 | * Team Invitation Mail View 128 | * -------------------------------------------------------------- 129 | * 130 | * This is the view that will be used to send the team invitation. 131 | */ 132 | 'team_invitation_mail_view' => 'filament-saas-panel::emails.team-invitation', 133 | 134 | /** 135 | * -------------------------------------------------------------- 136 | * OTP Rate Limit 137 | * -------------------------------------------------------------- 138 | * 139 | * This is the rate limit for the OTP. 140 | */ 141 | 'otp_rate_limit' => 5, 142 | 143 | /** 144 | * -------------------------------------------------------------- 145 | * Throttle OTP 146 | * -------------------------------------------------------------- 147 | * 148 | * This is the throttle for the OTP. 149 | */ 150 | 'throttle_otp' => 5, 151 | ]; 152 | -------------------------------------------------------------------------------- /src/FilamentSaasPanelServiceProvider.php: -------------------------------------------------------------------------------- 1 | commands([ 25 | \TomatoPHP\FilamentSaasPanel\Console\FilamentSaasPanelInstall::class, 26 | ]); 27 | 28 | // Register Config file 29 | $this->mergeConfigFrom(__DIR__.'/../config/filament-saas-panel.php', 'filament-saas-panel'); 30 | 31 | // Publish Config 32 | $this->publishes([ 33 | __DIR__.'/../config/filament-saas-panel.php' => config_path('filament-saas-panel.php'), 34 | ], 'filament-saas-panel-config'); 35 | 36 | // Register Migrations 37 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); 38 | 39 | // Publish Migrations 40 | $this->publishes([ 41 | __DIR__.'/../database/migrations' => database_path('migrations'), 42 | ], 'filament-saas-panel-migrations'); 43 | // Register views 44 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'filament-saas-panel'); 45 | 46 | // Publish Views 47 | $this->publishes([ 48 | __DIR__.'/../resources/views' => resource_path('views/vendor/filament-saas-panel'), 49 | ], 'filament-saas-panel-views'); 50 | 51 | // Register Langs 52 | $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'filament-saas-panel'); 53 | 54 | // Publish Lang 55 | $this->publishes([ 56 | __DIR__.'/../resources/lang' => base_path('lang/vendor/filament-saas-panel'), 57 | ], 'filament-saas-panel-lang'); 58 | 59 | // Register Routes 60 | $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); 61 | 62 | $this->publishes([ 63 | __DIR__.'/../publish/migrations/create_teams_table.php' => database_path('migrations/'.date('Y_m_d_His', ((int) time()) + 1).'_create_teams_table.php'), 64 | __DIR__.'/../publish/migrations/create_team_invitations_table.php' => database_path('migrations/'.date('Y_m_d_His', ((int) time()) + 2).'_create_team_invitations_table.php'), 65 | __DIR__.'/../publish/migrations/create_team_user_table.php' => database_path('migrations/'.date('Y_m_d_His', ((int) time()) + 3).'_create_team_user_table.php'), 66 | ], 'filament-saas-teams-migrations'); 67 | 68 | $this->publishes([ 69 | __DIR__.'/../publish/Team.php' => app_path('Models/Team.php'), 70 | __DIR__.'/../publish/TeamInvitation.php' => app_path('Models/TeamInvitation.php'), 71 | __DIR__.'/../publish/Membership.php' => app_path('Models/Membership.php'), 72 | ], 'filament-saas-teams-models'); 73 | 74 | if (class_exists(Jetstream::class)) { 75 | Jetstream::useUserModel(config('filament-saas-panel.user_model')); 76 | Jetstream::useTeamModel(config('filament-saas-panel.team_model')); 77 | Jetstream::useMembershipModel(config('filament-saas-panel.membership_model')); 78 | Jetstream::useTeamInvitationModel(config('filament-saas-panel.team_invitation_model')); 79 | Jetstream::$registersRoutes = false; 80 | Fortify::$registersRoutes = false; 81 | 82 | Jetstream::defaultApiTokenPermissions(['read']); 83 | } 84 | 85 | Livewire::component('sanctum-tokens', SanctumTokens::class); 86 | Livewire::component('otp', Otp::class); 87 | Livewire::component('notifications', Notifications::class); 88 | } 89 | 90 | public function boot(): void 91 | { 92 | $this->configurePermissions(); 93 | } 94 | 95 | /** 96 | * Configure the permissions that are available within the application. 97 | */ 98 | protected function configurePermissions(): void 99 | { 100 | Jetstream::role('admin', trans('filament-saas-panel::messages.roles.admin.name'), [ 101 | 'create', 102 | 'read', 103 | 'update', 104 | 'delete', 105 | ])->description(trans('filament-saas-panel::messages.roles.admin.description')); 106 | 107 | Jetstream::role('user', trans('filament-saas-panel::messages.roles.user.name'), [ 108 | 'read', 109 | 'update', 110 | ])->description(trans('filament-saas-panel::messages.roles.user.description')); 111 | 112 | Jetstream::permissions([ 113 | 'create', 114 | 'read', 115 | 'update', 116 | 'delete', 117 | ]); 118 | 119 | /** 120 | * Disable Fortify routes 121 | */ 122 | Fortify::$registersRoutes = false; 123 | 124 | /** 125 | * Disable Jetstream routes 126 | */ 127 | Jetstream::$registersRoutes = false; 128 | 129 | /** 130 | * Listen and create personal team for new accounts 131 | */ 132 | Event::listen( 133 | Registered::class, 134 | CreatePersonalTeam::class, 135 | ); 136 | 137 | /** 138 | * Listen and switch team if tenant was changed 139 | */ 140 | Event::listen( 141 | TenantSet::class, 142 | SwitchTeam::class, 143 | ); 144 | } 145 | } 146 | --------------------------------------------------------------------------------