Table column that shows Pivo columns

I can't get pivot columns to show up in a table. Not sure what I'm doing wrong. when I print the column of the relationship, it shows the pivot data in json form so its got the data. But if I do "connections.pivot_column" nothing shows. "connections.pivot.column" doesn't work. I created a relationship manager. the relation has withPivot. Not sure what I'm missing. The docs don't really show how to do it.
Tables\Columns\TextColumn::make('connections.synchronized_at')
->label('Sync at'),

public function connections():belongsToMany
{
return $this->belongsToMany(Connection::class,'client_connection','client_id','connection_id')->withPivot('is_synchronized','synchronized_at','custom_id');
}
Tables\Columns\TextColumn::make('connections.synchronized_at')
->label('Sync at'),

public function connections():belongsToMany
{
return $this->belongsToMany(Connection::class,'client_connection','client_id','connection_id')->withPivot('is_synchronized','synchronized_at','custom_id');
}
1 Reply
thedangler
thedanglerOP5mo ago
To get it working I had to do
Tables\Columns\TextColumn::make('connections.client_connection')
->getStateUsing(function(Model $record) {
return $record->connections()->first()?->pivot->synchronized_at;
})
->dateTime()
->label('Sync at'),
Tables\Columns\TextColumn::make('connections.client_connection')
->getStateUsing(function(Model $record) {
return $record->connections()->first()?->pivot->synchronized_at;
})
->dateTime()
->label('Sync at'),
not sure why when it has the pivot data in the connections.

Did you find this page helpful?