Tenant user pivot values

Hey, I have a fairly standard tenant setup and I have a users resource to show the tenant users. My "tenant" is a Company. So a company belongsToMany Users and a users belongsToMany Companies with the pivot table having a column role. Listing the users is working just fine, but the role is not showing (or none of the pivot values). This is the relationship on the Users model:
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class)
->withTimestamps()
->withPivot([
'created_at',
'updated_at',
'role',
'added_by_user_id',
])
->using(CompanyUserPivot::class);
}
public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class)
->withTimestamps()
->withPivot([
'created_at',
'updated_at',
'role',
'added_by_user_id',
])
->using(CompanyUserPivot::class);
}
I have the same thing on the Company model, just the reverse users(). I have a pivot class that is casting the role to a enum and the added_by_user_id is a relationship to a user. I understand that I have to convert the enum into a string, but if I add TextColumn::make("role") to the table, I expected to get an error saying something like cannot convert enum to string, but I get this instead: App\Models\User::role must return a relationship instance, but "null" was returned. Was the "return" keyword used? Am I missing something essential here? I use pivot values many places like this, but this one was not working. Let me know if you need more data Thank you!
0 Replies
No replies yetBe the first to reply to this messageJoin