Skip to content

uccellolabs/filament-tenancy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest Version on Packagist Total Downloads

Filament Tenancy

Easy way to manage tenancy with filament.

Installation

You can install the package via composer:

composer require uccellolabs/filament-tenancy

Configuration

Edit app/Models/User.php and add the following code:

use Uccellolabs\FilamentTenancy\Support\Traits\UserBelongsToTenant;

class User extends Authenticatable
{
    use UserBelongsToTenant;

    protected $fillable = [
        // ...
        'current_tenant_id',
    ];
}

Edit app/Filament/Resources/UserResource/Pages/ListUsers.php and add the following code:

use Uccellolabs\FilamentTenancy\Support\Traits\CurrentTenant;

class ListUsers extends ListRecords
{
    use CurrentTenant;

    protected function getTableQuery(): Builder
    {
        $userIds = $this->getCurrentTenant()?->users()->pluck('users.id') ?? [];

        return User::whereIn('id', $userIds);
    }
}

Usage

use Uccellolabs\FilamentTenancy\Support\Traits\CurrentTenant;

Add a column named tenant_id in your table and add the following code in your Model:

use Uccellolabs\FilamentTenancy\Support\Traits\BelongsToTenant;

class YourModel extends Model
{
    use BelongsToTenant;
}

Credits

License

The MIT License (MIT). Please see License File for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published