F
Filament12mo ago
nowak

TextColumn get relationship record

Is it possible to get the $record of the relationship of a resource when creating a TextColumn like this:
Tables\Columns\TextColumn::make('skus.price')
->label('Price')
->listWithLineBreaks()
->formatStateUsing(function ($state, $record) {
\Log::info('Current record:', [$record]);
return $state;
}),
Tables\Columns\TextColumn::make('skus.price')
->label('Price')
->listWithLineBreaks()
->formatStateUsing(function ($state, $record) {
\Log::info('Current record:', [$record]);
return $state;
}),
This was added to my ProductResource, where the above log output gives the product record. Is it somehow possible to get the sku record that the price belongs to instead?
Solution:
no, there is not currently a way to do that, but you could guess which sku it is based on the price
Jump to solution
4 Replies
Dan Harrin
Dan Harrin12mo ago
$record->skus
nowak
nowakOP12mo ago
Thanks, but I was more thinking of getting each individual sku record. Because when there is a has many relationship, the price for all of the resources sku records will be rendered. Here I would want to for example add an icon for each sku record, which would depend on $sku->attributeValues
Solution
Dan Harrin
Dan Harrin12mo ago
no, there is not currently a way to do that, but you could guess which sku it is based on the price
nowak
nowakOP12mo ago
Thanks @Dan Harrin ! It lead me in the right direction, where I can get the sku record in my case with $record->skus->firstWhere('price', $state).

Did you find this page helpful?