F
Filament9mo ago
Sidem

print function value

HI, the solution is probably very stupid but I haven't found it, but I would like to display the result of a function of a model in a column. The function is in my User model and returns a number that the column should display (so each row will have a different number in the column because it launches the function for a different user each time)
4 Replies
toeknee
toeknee9mo ago
->formatStateUsing(fn($record) => dump($record)) will dump the column record and you can see the data returned.
Sidem
SidemOP9mo ago
But when i do this, nothing is displayed :
Tables\Columns\TextColumn::make('number')->sortable()
->formatStateUsing(fn (User $record) => $record->calcul()),


---
Model User :
public function calcul(){
return 4
}
Tables\Columns\TextColumn::make('number')->sortable()
->formatStateUsing(fn (User $record) => $record->calcul()),


---
Model User :
public function calcul(){
return 4
}
for information, the column "number" didn't exist on my table user, but i can't put nothing else
toeknee
toeknee9mo ago
Tables\Columns\TextColumn::make('calcul')->sortable(),


---
Model User :
public function calcul(){
return 4
}
Tables\Columns\TextColumn::make('calcul')->sortable(),


---
Model User :
public function calcul(){
return 4
}
Dennis Koch
Dennis Koch9mo ago
number is null, therefore it's not rendered. You need getStateUsing() instead
Want results from more Discord servers?
Add your server