User.php
// User.php
class User extends Authenticatable implements FilamentUser, HasTenants
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
public function getTenants(Panel $panel): array|Collection
{
return $this->teams;
}
public function teams(): BelongsToMany
{
return $this->belongsToMany(Team::class);
}
public function canAccessTenant(Model $tenant): bool
{
return $this->teams()->whereKey($tenant)->exists();
}
public function canAccessPanel(Panel $panel): bool
{
return true;
}
}
User.php
// User.php
class User extends Authenticatable implements FilamentUser, HasTenants
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
protected $fillable = [
'name',
'email',
'password',
];
public function getTenants(Panel $panel): array|Collection
{
return $this->teams;
}
public function teams(): BelongsToMany
{
return $this->belongsToMany(Team::class);
}
public function canAccessTenant(Model $tenant): bool
{
return $this->teams()->whereKey($tenant)->exists();
}
public function canAccessPanel(Panel $panel): bool
{
return true;
}
}