Filament Companies

repository·5.x·Indexed 43 days ago

https://github.com/andrewdwallo/filament-companies

A multi-tenant authentication and authorization solution for Filament designed for company-based tenancy. It provides features including Socialite integration, employee invitations, role and permission management, personal profile management, and personal access tokens.

Tokens
9.4K
Snippets
31
Records
38
Agent score
56%

What's inside Filament Companies

  1. Upgrade from FilamentCompanies 4.x to 5.x

    5.x

    In version 5.x, company features are no longer enabled automatically by calling companies(). To follow the principle of least privilege, you must now explicitly enable each specific feature you want to use. Calling companies(invitations: true) only enables basic company support; you must chain additional methods to enable other functionalities.

    // 5.x Configuration Example
    FilamentCompanies::make()
        ->companies(invitations: true)           // Only enables basic company support
        ->updateCompanyInformation()             // Explicitly enable company name updates
        ->manageCompanyEmployees()               // Explicitly enable employee management
        ->companyDeletion()                      // Explicitly enable company deletion
  2. Customize the Privacy Policy template

    5.x
    The application includes a markdown stub for the Privacy Policy located at stubs/resources/markdown/policy.md. You should edit this file to define the actual privacy policy for your application, replacing the placeholder Lorem Ipsum text with your specific legal disclosures regarding information collection, log data, cookies, and service providers.
  3. Configure Email Verification for User Profiles

    5.x

    If using Laravel's email verification, you must ensure the verification URL is correctly registered so it works on the user profile page. You can do this in two ways:

    Option 1: Using the VerifyEmail::createUrlUsing callback (Recommended) Add this to your AppServiceProvider's boot method:

    use Filament\Facades\Filament;
    use Filament\Notifications\Auth\VerifyEmail;
    
    VerifyEmail::createUrlUsing(function ($notifiable) {
        return Filament::getVerifyEmailUrl($notifiable);
    });

    Option 2: Registering a manual route Add this to your routes/web.php:

    use Filament\Http\Controllers\Auth\EmailVerificationController;
    
    Route::get('/email/verify/{id}/{hash}', [EmailVerificationController::class, '__invoke'])
        ->middleware(['signed'])
        ->name('verification.verify');
  4. Set up Socialite credentials and Redirect URIs

    5.x

    To use Socialite providers, add the credentials to your config/services.php file.

    Critical: The Redirect URI must follow the pattern: APP_URL/company/oauth/provider/callback (e.g., https://your-app.com/company/oauth/github/callback).

    // config/services.php
    'github' => [
        'client_id' => env('GITHUB_CLIENT_ID'),
        'client_secret' => env('GITHUB_CLIENT_SECRET'),
        'redirect' => 'https://filament.test/company/oauth/github/callback',
    ],
  5. Create a custom theme for the Company panel

    5.x

    Because the package registers a company panel, you must create a custom Tailwind theme to ensure the package's styles are processed.

    1. Create a custom theme following the Filament documentation.
    2. Add the package's vendor directory to your custom theme's CSS file (e.g., resources/css/filament/company/theme.css) using the @source directive.
    @source '../../../../vendor/andrewdwallo/filament-companies/resources/views';
  6. Set the Company Panel as the Default Panel

    5.x

    To ensure users land on the Company panel's Register or Login pages when visiting the Laravel Welcome page, you must:

    1. Remove the ->default() method from your User panel.
    2. Apply the ->default() method to your Company panel configuration.
  7. Install Filament Companies

    5.x

    To install the package, require it via Composer and then run the scaffold command. The scaffold command will prompt you to choose between the Base package or enabling Socialite support.

    Prerequisites:

    • A fresh Laravel project.
    • A configured database.
    • Filament Panel Builder installed and a panel created via php artisan filament:install --panels.
    composer require andrewdwallo/filament-companies
    
    php artisan filament-companies:install
    
    php artisan migrate:fresh
  8. Upgrade from FilamentCompanies 3.x to 4.x

    5.x

    Upgrading from 3.x to 4.x involves replacing several classes with Enums and updating dependencies.

    Dependency Updates

    1. Ensure your application follows the Laravel 11 Upgrade Guide.
    2. Update andrewdwallo/filament-companies to ^4.0 in composer.json.
    3. Run composer update.

    Class Removals

    The following classes have been removed:

    • Wallo ilament-companies\Features (Methods moved to the main FilamentCompanies class)
    • Wallo\FilamentCompanies\Providers (Replaced by Wallo\FilamentCompanies\Enums\Provider enum)
    • Wallo\FilamentCompanies\Socialite (Replaced by Wallo\FilamentCompanies\Enums\Feature enum)
    • MakeUserCommand (Removed as it is no longer necessary)

    Migration Steps for Socialite Providers

    Replace Wallo\FilamentCompanies\Providers with the Wallo\FilamentCompanies\Enums\Provider enum. Use enum cases for enabling and the isEnabled() method for checking status.

    Migration Steps for Socialite Features

    Replace Wallo\FilamentCompanies\Socialite with the Wallo\FilamentCompanies\Enums\Feature enum. Use enum cases for enabling and the isEnabled() method for checking status.

  9. Configure the User Panel for Profile and Tokens

    5.x

    The package requires a "User" panel (which can be your default Admin panel or a dedicated user panel) to host the Profile and Personal Access Tokens pages. You must register these pages in your panel configuration.

    use Walloilament-companies\Pages\User\PersonalAccessTokens;
    use Wallo\FilamentCompanies\Pages\User\Profile;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->pages([
                Profile::class,
                PersonalAccessTokens::class,
            ]);
    }
  10. Customize the Terms of Service template

    5.x

    The stubs/resources/markdown/terms.md file serves as a template for the application's Terms of Service. To define your application's specific legal terms, edit this file directly. The template includes placeholder sections for:

    • Introduction: General overview of the service.
    • Usage Terms: Rules regarding how the service should be used.
    • User Conduct: Expectations for user behavior.
    • Content Ownership: Definitions of who owns user-generated content.
    • Limitations of Liability: Legal disclaimers and liability constraints.
  11. Configure Socialite providers and features

    5.x

    By default, the GitHub provider is enabled. You can add or remove any provider supported by Laravel Socialite using the Provider enum. You can also enable specific features like RememberSession or LoginOnRegistration within the socialite() method of the FilamentCompanies plugin configuration.

    Note: If using Twitter, you must choose either Twitter (OAuth1) or TwitterOAuth2 (OAuth2); do not use both.

    use Filament\Panel;
    use Wallo\FilamentCompanies\FilamentCompanies;
    use Wallo\FilamentCompanies\Enums\Feature;
    use Wallo\FilamentCompanies\Enums\Provider;
    
    class FilamentCompaniesServiceProvider extends PanelProvider
    {
        public function panel(Panel $panel): Panel
        {
            return $panel
                // ...
                ->plugin(
                    FilamentCompanies::make()
                        ->socialite(
                            providers: [
                                Provider::Github,
                                Provider::Gitlab,
                                Provider::Google,
                                Provider::Facebook,
                                Provider::Linkedin,
                                Provider::LinkedinOpenId,
                                Provider::Bitbucket,
                                Provider::Slack,
                                Provider::Twitter,
                                Provider::TwitterOAuth2,
                            ],
                            features: [
                                Feature::RememberSession,
                                Feature::ProviderAvatars,
                                Feature::GenerateMissingEmails,
                                Feature::LoginOnRegistration,
                                Feature::CreateAccountOnFirstLogin,
                            ]
                        )
                );
        }
    }
  12. Configure Profile Features

    5.x

    You can selectively enable or disable profile features by calling their respective methods on the FilamentCompanies instance within your PanelProvider. If a method is omitted, the feature is disabled by default.

    Available profile features:

    • updateProfileInformation(): Enables updating profile information.
    • updatePasswords(): Enables password updates.
    • setPasswords(): Enables setting passwords (only if Socialite is enabled).
    • connectedAccounts(): Enables connected account management (only if Socialite is enabled).
    • manageBrowserSessions(): Enables browser session management.
    • accountDeletion(): Enables account deletion.
    ->plugin(
        FilamentCompanies::make()
            ->updateProfileInformation()
            ->updatePasswords()
            ->setPasswords()
            ->connectedAccounts()
            ->manageBrowserSessions()
            ->accountDeletion()
    );