Unable to access pivot data on resource when using Multi-tenancy
Hi,
I've added a pivot column
is_active
to the relation between users and tenants. But it's value seems inaccessible on the UserResource
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Tenant extends Model
{
// ...
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'tenant_users')
->withPivot([
'is_active',
]);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Tenant extends Model
{
// ...
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'tenant_users')
->withPivot([
'is_active',
]);
}
}
<?php
namespace App\Models;
use Filament\Models\Contracts\HasDefaultTenant;
use Filament\Models\Contracts\HasTenants;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements HasDefaultTenant, HasTenants
{
// ...
public function tenants(): BelongsToMany
{
return $this->belongsToMany(Tenant::class, 'tenant_users')
->withPivot([
'is_active',
]);
}
}
<?php
namespace App\Models;
use Filament\Models\Contracts\HasDefaultTenant;
use Filament\Models\Contracts\HasTenants;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements HasDefaultTenant, HasTenants
{
// ...
public function tenants(): BelongsToMany
{
return $this->belongsToMany(Tenant::class, 'tenant_users')
->withPivot([
'is_active',
]);
}
}
<?php
namespace App\Filament\AppPanel\Resources;
use App\Models\User;
use Filament\Resources\Resource;
use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static ?string $tenantOwnershipRelationshipName = 'tenants';
// ...
public static function table(Table $table): Table
{
return $table
->columns([
IconColumn::make('is_active')
->boolean()
]);
}
}
<?php
namespace App\Filament\AppPanel\Resources;
use App\Models\User;
use Filament\Resources\Resource;
use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static ?string $tenantOwnershipRelationshipName = 'tenants';
// ...
public static function table(Table $table): Table
{
return $table
->columns([
IconColumn::make('is_active')
->boolean()
]);
}
}
0 Replies