Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rmznatly's avatar

How do I get formatted table records?

How can I get table data in trait? table->getRecords() gets the database data. This is not enough for me because I show the data in the table by formatting it. Is there any way to get the fully formatted data in the table?

0 likes
9 replies
Sinnbeck's avatar

What do you mean by formatted? How are you formatting it? An accessor?

rmznatly's avatar

@Sinnbeck For example, movement_type value comes IN with db. I show the value that matches the FormatStateUsing enum in the table. When I get the records as I mentioned, it will be necessary to redefine this and similar formats for each column. And I am trying to write a triad for many tables because I need a dynamic structure. So I need to get what is in the table as it is.

Tray2's avatar

@rmznatly The what, the what and the what? That sentence makes n o sense to me whatsoever.

rmznatly's avatar

@Tray2 Since English is not my first language, I can make spelling mistakes.

rmznatly's avatar

@Sinnbeck

Tables\Columns\TextColumn::make('movement_model') ->label('Hareket Türü') ->icon(function ($state) { if (class_exists($state)) { return $state::getNavigationIcon(); } else { return 'heroicon-o-bars-3-bottom-left'; } }) ->formatStateUsing(fn($record) => CustomerAccountFinanceMovementType::tryFrom($record->movement_name)?->label() ?? 'N/A') ->size(TextColumnSize::Medium) ->badge() ->color(fn($record) => CustomerAccountFinanceMovementType::tryFrom($record->movement_name)?->color() ?? 'gray'), ​

Incoming “CASH_IN” value is converted to “Cash In” with formatStateUsing.

trait PdfExport { public function exportToPdf() { $data = $this->table->getRecords(); dd($data); .... } } ​

When I get the table records here, the data comes with the value “CASH_IN”, not “Cash In”. getRecords brings the records in their original form. Is there any way to get the transformed data in the table? This is exactly my question.

Tray2's avatar

@rmznatly Mine neither, and I wasn't refering to the spelling, just the problems I had trying the deschifer what you meant.

rmznatly's avatar

@Tray2 Thx. I tried to explain my problem with detailed examples in my previous reply. Do you have a suggestion?

YGS's avatar

@rmznatly you can mutate it in the model, you can also map using the map method after you get the data from the query, you can also try using a Resource class

Please or to participate in this conversation.