百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

filament-companies

> 后端框架
开源

一个专为 Filament 设计的全面的 Laravel 身份验证和授权系统,重点关注多租户公司管理。

353 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个专为 Filament 设计的全面的 Laravel 身份验证和授权系统,重点关注多租户公司管理。

Filament Companies

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

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

Getting Started

  • Create a fresh Laravel Project
  • Configure your database
  • Install the Panel Builder

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

bash
php artisan filament:install --panels

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

Installation

Install the package

bash
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.

bash
php artisan filament-companies:install

Run migrations:

bash
php artisan migrate:fresh

Preparing Your Application

Demo

If you encounter any issues while setting up your application with this package, refer to the example implementation here: Filament Companies Example App.

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.

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:

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

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:

php
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

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:

…

If 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:

php
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:

php
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

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

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

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

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

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

Email Verification

If you are using email verification 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

Place this in your AppServiceProvider's boot method:

php
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

Place this in routes file - typically web.php:

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

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

Usage & Configuration

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.

php
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

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:

…

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:

php
use App\Livewire\CustomComponent;

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

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:

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

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:

php
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:

blade

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

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

    
        
            {{ $this->form }}

            

        
    

Configuring Company Settings Features

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

php
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

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

php
use App\Livewire\CustomCompanyComponent;

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

Sorting Company Settings Components

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

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

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:

php
use App\Livewire\CustomCompanyComponent;

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

Profile Photos

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

php
use Filament\Panel;
use Wallo\FilamentCompanies\FilamentCompanies;

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                Fi

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPauthenticationauthorizationfilamentlaravel

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架