F
Filament4w ago
Sayy

how to get data relationship from table text column in description

i just want to group like stock quantity then below its description from relationship can or not ?
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' |');
}),
Tables\Columns\TextColumn::make('productItems.satuan')
->numeric()
->label('Satuan')
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' | ');
}),
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' |');
}),
Tables\Columns\TextColumn::make('productItems.satuan')
->numeric()
->label('Satuan')
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' | ');
}),
No description
Solution:
solve with code like this :
->description(fn (Product $record): string => $record->productItems()->pluck('satuan')->implode(', '))
->description(fn (Product $record): string => $record->productItems()->pluck('satuan')->implode(', '))
...
Jump to solution
6 Replies
Sayy
Sayy4w ago
i just want like this but how to get data description relationship ?
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->description('Box | Strip | Biji'), //how to get data relationship with description ?
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->description('Box | Strip | Biji'), //how to get data relationship with description ?
No description
Chrispian
Chrispian4w ago
Description supports callbacks. There is an example in the docs, just reference the relationship on your model as normal within the callback. Assuming the relationship name is stock and you want to show the stock's description:
TextColumn::make('productItems.stock')
->description(fn (YourModel $record): string => $record->stock->description)
TextColumn::make('productItems.stock')
->description(fn (YourModel $record): string => $record->stock->description)
https://filamentphp.com/docs/3.x/tables/columns/text#displaying-a-description You may have to tweak for your use case but this is what I think you're looking for.
Sayy
Sayy4w ago
already try like this but i got error like this
No description
Sayy
Sayy4w ago
my code
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->description(fn (Product $record): string => $record->productItems->satuan)
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' | ');
}),
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->description(fn (Product $record): string => $record->productItems->satuan)
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' | ');
}),
already try then how to get data string ?
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->description(fn (Product $record): string => $record->productItems()->pluck('satuan'))
->placeholder('-')
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' | ');
}),
Tables\Columns\TextColumn::make('productItems.stock')
->numeric()
->label('Stock Satuan')
->description(fn (Product $record): string => $record->productItems()->pluck('satuan'))
->placeholder('-')
->formatStateUsing(function ($state) {
return str($state)->replace(',', ' | ');
}),
Sayy
Sayy4w ago
No description
Solution
Sayy
Sayy4w ago
solve with code like this :
->description(fn (Product $record): string => $record->productItems()->pluck('satuan')->implode(', '))
->description(fn (Product $record): string => $record->productItems()->pluck('satuan')->implode(', '))