How to create custom column in the table?

I want to add custom column and its value not related to value of model, i tried by adding TextColumn with custom name but it doesn't show it's value...
8 Replies
hayvern
hayvern12mo ago
How are you feeding data to the column? Using a closure?
03_dotuan
03_dotuanOP12mo ago
i just using Table and Text Column like this: Tables\Columns\TextColumn::make('main_user_id') ->label('子供数') ->formatStateUsing(fn ($record) => $record->children->count()),
lazydog
lazydog12mo ago
you are in the right path, but dd the value of the record or record->children if it has a value
KeyMe
KeyMe12mo ago
following this thread as well
lazydog
lazydog12mo ago
Or append your new colum from your model, then you can use that appended column in your Table
Dennis Koch
Dennis Koch12mo ago
Use getStateUsing(). formatStateUsing() won't work, because there is no state to format.
03_dotuan
03_dotuanOP12mo ago
Thank you guys, i'll try it

Did you find this page helpful?