#Issue displaying & editing pivot field (role) in multi-tenant UserResource

3 messages · Page 1 of 1 (latest)

pliant quiver
#

Hi, I’m working on a multi-tenant Laravel Filament app with companies and users in a many-to-many relationship.
The pivot table is company_user and contains a role field.

I’ve set up my UserResource like this:
protected static ?string $tenantOwnershipRelationshipName = 'companies';

This correctly filters users to the current tenant.

In my table, I want to show name, email, and role:

Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('role'),

name and email display fine, but role does not show.
I expected it to work like how relationship managers handle pivot fields.

Models

User model:

public function companies(): BelongsToMany
{
    return $this->belongsToMany(Company::class)
        ->withPivot(['role'])
        ->withTimestamps();
}

Company model:

public function users(): BelongsToMany
{
    return $this->belongsToMany(User::class)
        ->withPivot(['role'])
        ->withTimestamps();
}

Form fields in UserResource:

Forms\Components\TextInput::make('name')
    ->required()
    ->maxLength(255),

Forms\Components\TextInput::make('email')
    ->email()
    ->required()
    ->maxLength(255),

Forms\Components\Select::make('role')
    ->required()
    ->default(CompanyRole::Admin)
    ->options(CompanyRole::class),

The problems I’m facing:
1. In the table, role does not display.
2. When creating a user, Filament inserts data into the pivot table but ignores the value from the role select — it always uses the DB default (member).
3. When editing a user, the form loads name and email, but does not load the current role from the pivot table.

How can I correctly display, load, and save a pivot field (role) in this UserResource with multi-tenancy enabled?

spring heartBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

pliant quiver
#

I couldn’t figure out a clean solution, so I ended up moving Users management from a dedicated resource into the Company resource (the tenant in my case) using a relation manager.

Inside the Company resource, I now display the related users so they can be managed directly.
The previous UX felt awkward, users had to click Companies (which only showed the current tenant), open its details, and only then manage the users.

Instead, I added a user management section directly to the Tenant Profile page. Now, when a user visits tenant settings, they see the tenant’s info and, right below it, the related users. This feels much more natural and streamlined.

I found the way to implement it here:
https://www.answeroverflow.com/m/1250377468712583220

How can I add a RelationManager to the EditTenantProfil page? I tried adding getRelations() to the EditTeamProfile, but it doesn't show up. I figure something about a custom view, but I am not that experienced in custom views?

I have a TeamResource with Create/Edit, where the UserRelationManager works perfectly, but not on the tenant edit prof...