PHPackages                             andrewdwallo/filament-companies - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. andrewdwallo/filament-companies

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

andrewdwallo/filament-companies
===============================

A comprehensive Laravel authentication and authorization system designed for Filament, focusing on multi-tenant company management.

v5.0.2(4mo ago)35156.4k↓57.9%72[1 issues](https://github.com/andrewdwallo/filament-companies/issues)[4 PRs](https://github.com/andrewdwallo/filament-companies/pulls)1MITPHPPHP ^8.2CI passing

Since Dec 27Pushed 4mo ago7 watchersCompare

[ Source](https://github.com/andrewdwallo/filament-companies)[ Packagist](https://packagist.org/packages/andrewdwallo/filament-companies)[ Docs](https://github.com/andrewdwallo/filament-companies)[ RSS](/packages/andrewdwallo-filament-companies/feed)WikiDiscussions 5.x Synced 3d ago

READMEChangelog (10)Dependencies (24)Versions (88)Used By (1)

[![gif (1)](https://user-images.githubusercontent.com/104294090/221399175-add7c34b-4887-49b7-9061-6781f6391409.gif)](https://user-images.githubusercontent.com/104294090/221399175-add7c34b-4887-49b7-9061-6781f6391409.gif)

 [ ![FILAMENT 4.x](https://camo.githubusercontent.com/13befbe0cffd101b2484ce1cdd985dabcddcbf1176d17a675674d53af99cfdbc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46494c414d454e542d342e782d4542423330343f7374796c653d666f722d7468652d6261646765) ](https://filamentphp.com) [ ![Packagist](https://camo.githubusercontent.com/cc22a08d9df378266899836b51510b085eaf252ca9aef3a3081977a257beb3f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e647265776477616c6c6f2f66696c616d656e742d636f6d70616e6965732e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374) ](https://packagist.org/packages/andrewdwallo/filament-companies) [ ![Downloads](https://camo.githubusercontent.com/b4662597cf1c3b609a854b2a650196642bca92d95a533f29e1bd044f29627e1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647265776477616c6c6f2f66696c616d656e742d636f6d70616e6965733f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d72656426636f6c6f723d726564) ](https://packagist.org/packages/andrewdwallo/filament-companies/stats)

---

Filament Companies
==================

[](#filament-companies)

A comprehensive multi-tenant authentication and authorization solution designed for Filament, with a focus on company-based tenancy.

- 🔥 **Socialite**
- 🔥 **Terms &amp; Privacy Policy**
- 🔥 **Password Reset via Email**
- 🔥 **Personal Profile Management**
- 🔥 **Browser Session Management**
- 🔥 **Sanctum**
- 🔥 **Company Management**
- 🔥 **Employee Invitations via Email**
- 🔥 **Roles &amp; Permissions**
- 🔥 **Auto-Accept Invitations**

Getting Started
===============

[](#getting-started)

- Create a fresh Laravel Project
- Configure your database
- Install the [Panel Builder](https://filamentphp.com/docs/4.x/introduction/installation#installing-the-panel-builder)

After installing the Panel Builder, ensure you create a panel using the following command:

```
php artisan filament:install --panels
```

> 📝 If you've followed the Panel Builder documentation, you should have already done this.

Installation
============

[](#installation)

Install the package

```
composer require andrewdwallo/filament-companies
```

Execute the following Artisan command to scaffold the application. You will be prompted to choose between installing the **Base package** or enabling **Socialite** support.

```
php artisan filament-companies:install
```

Run migrations:

```
php artisan migrate:fresh
```

Preparing Your Application
==========================

[](#preparing-your-application)

### Demo

[](#demo)

If you encounter any issues while setting up your application with this package, refer to the example implementation here: [Filament Companies Example App](https://github.com/andrewdwallo/filament-companies-example-app).

### Creating a Theme

[](#creating-a-theme)

After installation, there will be a company panel registered for your application. It is located within the `FilamentCompaniesServiceProvider.php` file.

In order for Tailwind to process the CSS used within this package and for the company panel, a user must [create a custom theme](https://filamentphp.com/docs/4.x/styling/overview#creating-a-custom-theme).

Once the custom theme for the company panel is created, add this package's vendor directory to your `resources/css/filament/company/theme.css` file:

```
@source '../../../../vendor/andrewdwallo/filament-companies/resources/views';
```

### The User Panel

[](#the-user-panel)

As you may have noticed, after installation, there will be a company panel registered for your application. In order for this package to work you must also have a "User" panel to contain the Profile page and Personal Access Tokens page.

For this example, I will use the default panel that Filament provides when installing the panel builder, the "Admin" panel.

In your "Admin" panel, make sure to register the following pages:

```
use Wallo\FilamentCompanies\Pages\User\PersonalAccessTokens;
use Wallo\FilamentCompanies\Pages\User\Profile;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->pages([
            Profile::class,
            PersonalAccessTokens::class,
        ])
}
```

> 🛑 You may create a separate User Panel following the documentation for [creating a new panel](https://filamentphp.com/docs/4.x/panel-configuration#creating-a-new-panel)

Ensure users have a way to navigate to the Profile and Personal Access Tokens pages.

Users should also have a way to navigate back to the Company Panel.

You may use the following as a guide:

```
use Filament\Navigation\MenuItem;
use Filament\Navigation\NavigationItem;
use Illuminate\Support\Facades\Auth;
use Wallo\FilamentCompanies\Pages\User\PersonalAccessTokens;
use Wallo\FilamentCompanies\Pages\User\Profile;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->userMenuItems([
            'profile' => MenuItem::make()
                ->label('Profile')
                ->icon('heroicon-o-user-circle')
                ->url(static fn () => Profile::getUrl()),
            MenuItem::make()
                ->label('Company')
                ->icon('heroicon-o-building-office')
                ->url(static fn () => Pages\Dashboard::getUrl(panel: FilamentCompanies::getCompanyPanel(), tenant: Auth::user()->personalCompany())),
        ])
        ->navigationItems([
            NavigationItem::make('Personal Access Tokens')
                ->label(static fn (): string => __('filament-companies::default.navigation.links.tokens'))
                ->icon('heroicon-o-key')
                ->url(static fn () => PersonalAccessTokens::getUrl()),
        ])
}
```

If [**Auto-Accept Invitations**](#auto-accept-invitations) is enabled, the Company menu item logic must handle cases where the user does not have a personal company to avoid errors. One way to do this is as follows:

```
MenuItem::make()
    ->label('Company')
    ->icon('heroicon-o-building-office')
    ->url(static function (): ?string {
        $user = Auth::user();

        if ($company = $user?->primaryCompany()) {
            return Pages\Dashboard::getUrl(panel: FilamentCompanies::getCompanyPanel(), tenant: $company);
        }

        return Filament::getPanel(FilamentCompanies::getCompanyPanel())->getTenantRegistrationUrl();
    }),
```

Note

This modification is necessary because, when Auto-Accept Invitations is enabled, an invited user may not have a personal company. Without this adjustment, generating a URL with a `null` tenant may cause an error.

You may change the value used for the User Panel using the `id` of the panel:

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->userPanel('user')
            )
    }
}
```

> 🚧 Make sure to create a panel with the id you're passing

### The Default Panel

[](#the-default-panel)

If you want users to directly access the Company panel's Register or Login page from the Laravel Welcome page, ensure the Company panel is set as the default in Filament. This involves two key steps:

1. Remove Default from User Panel: Ensure the User panel or any previously default panel does not use the `->default()` method.
2. Set Company Panel as Default: Apply the `->default()` method to your Company panel configuration to make it the default entry point.

By making the Company panel the default, links to Register or Login on the Laravel Welcome page will lead directly to the Company panel's authentication pages.

### Translations and Views

[](#translations-and-views)

If you wish to translate the package, you may publish the language files using:

```
php artisan vendor:publish --tag=filament-companies-translations
```

If you wish to customize the views, you may publish them using:

```
php artisan vendor:publish --tag=filament-companies-views
```

### Email Verification

[](#email-verification)

If you are using [email verification](https://filamentphp.com/docs/4.x/users/overview#authentication-features) make sure to register your verify-email url. If this is not properly registerd, you may see errors on the user profile page. You can either add this via Filament's `VerifyEmail` facade or a new route in your app.

#### Registering the URL via the create URL Notification callback

[](#registering-the-url-via-the-create-url-notification-callback)

Place this in your `AppServiceProvider`'s boot method:

```
use Filament\Facades\Filament;
use Filament\Notifications\Auth\VerifyEmail;

// Verify email notification url
VerifyEmail::createUrlUsing(function ($notifiable) {
    return Filament::getVerifyEmailUrl($notifiable);
});
```

#### Registering your email verification route through a new route

[](#registering-your-email-verification-route-through-a-new-route)

Place this in routes file - typically `web.php`:

```
use Filament\Http\Controllers\Auth\EmailVerificationController;

Route::get('/email/verify/{id}/{hash}', [EmailVerificationController::class, '__invoke'])
    ->middleware(['signed'])
    ->name('verification.verify');
```

Usage &amp; Configuration
=========================

[](#usage--configuration)

### Switching the Current Company

[](#switching-the-current-company)

Filament has a built-in event that is fired when the application needs to set the tenant for the current request. This event is `Filament\Events\TenantSet`. If you would like to either enable or disable the ability to switch the current company, you may do so by using the `switchCurrentCompany()` method in your `FilamentCompaniesServiceProvider` class.

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->switchCurrentCompany()
            );
    }
}
```

Caution

This feature is a core part of the package and should typically remain enabled. Disabling it will prevent users from switching between companies, which may not be desirable for most use cases.

Configuring Profile Features
----------------------------

[](#configuring-profile-features)

You can selectively enable or disable certain profile features. If a feature is omitted, it will be disabled by default.

To do so, modify your `FilamentCompaniesServiceProvider` class as shown below:

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->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
            );
    }
}
```

### Customizing Components

[](#customizing-components)

Personalize your application by replacing default components with your own custom components. This is done by passing your custom component's class name to the component parameter of the relevant method.

Important

Your custom component must have a unique class name. This is crucial to prevent conflicts and ensure proper functioning, as Livewire differentiates components primarily by their class names. Even if your custom component is in a different namespace, having the same class name as a component in the package can lead to unexpected errors and behavior.

Here's an example of how to use a custom component for updating profile information:

```
use App\Livewire\CustomComponent;

FilamentCompanies::make()
    ->updateProfileInformation(component: CustomComponent::class);
```

### Sorting Components

[](#sorting-components)

If you would like to change the order of the profile features, you may do so by setting the `sort` parameter to the corresponding method.

The default sort order is as follows:

```
FilamentCompanies::make()
    ->updateProfileInformation(sort: 0)
    ->updatePasswords(sort: 1)
    ->setPasswords(sort: 2)
    ->connectedAccounts(sort: 3)
    ->manageBrowserSessions(sort: 4)
    ->accountDeletion(sort: 5);
```

### Adding Components

[](#adding-components)

If you would like to add custom profile components, you may do so by passing the component class name along with the sort order to the `addProfileComponents()` method:

```
use App\Livewire\CustomComponent;

FilamentCompanies::make()
    ->addProfileComponents([
        7 => CustomComponent::class,
    ]);
```

Within your component's view, you may use the grid section component to match the style of other components:

```

        {{ __('My Custom Component') }}

        {{ __('This is my custom component.') }}

            {{ $this->form }}

                    {{ __('Save') }}

```

Configuring Company Settings Features
-------------------------------------

[](#configuring-company-settings-features)

Similar to profile features, you can customize the company settings page by enabling specific features and customizing their components.

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->updateCompanyInformation()   // Enables updating company names
                    ->manageCompanyEmployees()     // Enables company employee management
                    ->companyDeletion()            // Enables company deletion
            );
    }
}
```

### Customizing Company Settings Components

[](#customizing-company-settings-components)

You can replace default company settings components with your own custom components:

```
use App\Livewire\CustomCompanyComponent;

FilamentCompanies::make()
    ->updateCompanyInformation(component: CustomCompanyComponent::class);
```

### Sorting Company Settings Components

[](#sorting-company-settings-components)

Change the order of company settings features by setting the `sort` parameter:

```
FilamentCompanies::make()
    ->updateCompanyInformation(sort: 0)
    ->manageCompanyEmployees(sort: 1)
    ->companyDeletion(sort: 2);
```

### Adding Company Settings Components

[](#adding-company-settings-components)

If you would like to add custom company settings components, you may do so by passing the component class name along with the sort order to the `addCompanyComponents()` method:

```
use App\Livewire\CustomCompanyComponent;

FilamentCompanies::make()
    ->addCompanyComponents([
        5 => CustomCompanyComponent::class,
    ]);
```

Profile Photos
--------------

[](#profile-photos)

To allow users to upload custom profile photos, you can enable this feature by including the `profilePhotos()` method in your `FilamentCompaniesServiceProvider`.

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->profilePhotos()
            )
    }
}
```

### Disk Storage

[](#disk-storage)

By default, the package uses Laravel's `public` disk for storing images. However, you can specify a different disk by passing the `disk` parameter.

```
FilamentCompanies::make()
    ->profilePhotos(disk: 's3')
```

### Storage Path

[](#storage-path)

If you want to store profile photos in a specific directory, you can set the `storagePath` parameter.

```
FilamentCompanies::make()
    ->profilePhotos(storagePath: 'profile-avatars')
```

Modals
------

[](#modals)

To adjust the layout and behavior of modals, use the `modals()` method. Below are the package's default settings:

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->modals(
                        width: '2xl',
                        alignment: 'center',
                        formActionsAlignment: 'center',
                        cancelButtonAction: false
                    )
            );
    }
}
```

Notifications
-------------

[](#notifications)

To configure the notifications that are sent by the package, use the `notifications()` method.

Unless specified otherwise, the package will send notifications. In order to disable notifications, you must pass `false` to the `notifications()` method.

```
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FilamentCompanies::make()
                    ->notifications(condition: false)
            );
    }
}
```

### Overriding Notifications

[](#overriding-notifications)

To override the default notifications sent by the package, you should provide the following methods for each corresponding action.

The parameters passed to each method are optional and may be omitted if not needed.

#### Update User Profile Information

[](#update-user-profile-information)

```
\App\Actions\FilamentCompanies\UpdateUserProfileInformation::class

/** @method void profileInformationUpdated(\Illuminate\Foundation\Auth\User|null $user = null, array|null $input = null) */
```

#### Update User Password

[](#update-user-password)

```
\App\Actions\FilamentCompanies\UpdateUserPassword::class

/** @method void passwordUpdated(\Illuminate\Foundation\Auth\User|null $user = null, array|null $input = null) */
```

#### Set User Password

[](#set-user-password)

```
\App\Actions\FilamentCompanies\SetUserPassword::class

/** @method void passwordSet(\Illuminate\Foundation\Auth\User|null $user, array|null $input = null) */
```

#### Update Company Name

[](#update-company-name)

```
\App\Actions\FilamentCompanies\UpdateCompanyName::class

/** @method void companyNameUpdated(\Illuminate\Foundation\Auth\User|null $user = null, \Illuminate\Database\Eloquent\Model|null $company = null, array|null $input = null) */
```

#### Invite Company Employee

[](#invite-company-employee)

```
\App\Actions\FilamentCompanies\InviteCompanyEmployee::class

/** @method void employeeInvitationSent(\Illuminate\Foundation\Auth\User|null $user = null, \Illuminate\Database\Eloquent\Model|null $company = null, string|null $email = null, string|null $role = null) */
```

#### Delete Company

[](#delete-company)

```
\App\Actions\FilamentCompanies\DeleteCompany::class

/** @method void companyDeleted(\Illuminate\Database\Eloquent\Model|null $company = null) */
```

#### Example

[](#example)

If you would like to override the notification that is sent when a user updates their password, you may do the following:

```
