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
How are you feeding data to the column? Using a closure?
i just using Table and Text Column like this: Tables\Columns\TextColumn::make('main_user_id')
->label('子供数')
->formatStateUsing(fn ($record) => $record->children->count()),
you are in the right path, but
dd
the value of the record
or record->children
if it has a valuefollowing this thread as well
Or append your new colum from your model, then you can use that appended column in your Table
Use
getStateUsing()
. formatStateUsing()
won't work, because there is no state to format.Also, there is a
->counts()
method:
https://filamentphp.com/docs/3.x/tables/columns/relationships#counting-relationshipsThank you guys, i'll try it