F
Filamentβ€’16mo ago
N. Jacobsen

Tenant dropdown selection broken

I've got this issue....
Solution:
Can you dd on $this->organizations in: public function getTenants(Panel $panel): Collection { return $this->organizations;...
Jump to solution
7 Replies
N. Jacobsen
N. JacobsenOPβ€’16mo ago
N. Jacobsen
N. JacobsenOPβ€’16mo ago
This is my user model:
class User extends Authenticatable implements FilamentUser, HasTenants
{
use HasApiTokens, HasFactory, Notifiable;

#.... un needed code for this case...

public function roles()
{
return $this->belongsToMany(Role::class);
}

public function organizations()
{
return $this->belongsToMany(Organization::class)->using(OrganizationUser::class)->withPivot('role_id');
}

public function getTenants(Panel $panel): Collection
{
return $this->organizations;
}

public function canAccessPanel(Panel $panel): bool
{
$roles = $this->roles;
if($roles->contains('slug', 'global-administrator')){return true;}
return false;
}

public function canAccessTenant(Model $tenant): bool
{
$roles = $this->roles;
if($roles->contains('slug', 'global-administrator')){return true;}
return $tenant->users->contains('id',$this->id);
}
}
class User extends Authenticatable implements FilamentUser, HasTenants
{
use HasApiTokens, HasFactory, Notifiable;

#.... un needed code for this case...

public function roles()
{
return $this->belongsToMany(Role::class);
}

public function organizations()
{
return $this->belongsToMany(Organization::class)->using(OrganizationUser::class)->withPivot('role_id');
}

public function getTenants(Panel $panel): Collection
{
return $this->organizations;
}

public function canAccessPanel(Panel $panel): bool
{
$roles = $this->roles;
if($roles->contains('slug', 'global-administrator')){return true;}
return false;
}

public function canAccessTenant(Model $tenant): bool
{
$roles = $this->roles;
if($roles->contains('slug', 'global-administrator')){return true;}
return $tenant->users->contains('id',$this->id);
}
}
Solution
toeknee
toekneeβ€’16mo ago
Can you dd on $this->organizations in: public function getTenants(Panel $panel): Collection { return $this->organizations; }
N. Jacobsen
N. JacobsenOPβ€’16mo ago
Fuck me your right
toeknee
toekneeβ€’16mo ago
πŸ˜‚ Thanks for the offer, I'm flattered.
N. Jacobsen
N. JacobsenOPβ€’16mo ago
Hhaha It's becuase i have two tables, RoleUser and OrgUser... Global Administrator needs access to everything and they are only mentioned in RoleUser not OrgUser which the model looks in.... God dammit
toeknee
toekneeβ€’16mo ago
that'll do it πŸ˜‰ we have bugs, but I'd be surprised if that was one πŸ˜„
Want results from more Discord servers?
Add your server