F
Filament16mo ago
*

formatStateUsing() and a nullable boolean column

I have a nullable boolean column in a table like:
$table->boolean('decision')->nullable();
$table->boolean('decision')->nullable();
In my Filament table, I'm trying to display 'Pending' for the null value and 'Accepted' or 'Rejected' correspondingly for true and false I do not get any $state or Model $record for the null values at all.
TextColumn::make('decision')
->badge()
->formatStateUsing(function (Model $record) {
dump($record);
})
...
TextColumn::make('decision')
->badge()
->formatStateUsing(function (Model $record) {
dump($record);
})
...
will not dump anything at all, but works as expected for the non-null values. same with
TextColumn::make('decision')
->badge()
->formatStateUsing(function (string $state) {
dump($state)
})
...
TextColumn::make('decision')
->badge()
->formatStateUsing(function (string $state) {
dump($state)
})
...
Any insight would be appreciated.
Solution:
Try getStateUsing(). null values are filteres and there is not formatStateUsing() for them
Jump to solution
5 Replies
Solution
Dennis Koch
Dennis Koch16mo ago
Try getStateUsing(). null values are filteres and there is not formatStateUsing() for them
*
*OP16mo ago
@Dennis Koch Ah, that makes sense. Do I simply use the HasState trait and call it the same way as formatStateUsing()? Interestingly fails with no errors (dropped connection) when I attempt to do that. Ah, hold on My bad, it was still trying to inject a string, which obviously would fail Injecting the Model, works as expected
Dennis Koch
Dennis Koch16mo ago
Not sure why you mention HasState trait now, since you didn't use that one before. But you can use getStateUsing() prettry much the same like your first example
*
*OP16mo ago
Thanks @Dennis Koch, you saved me a lot of time I would've spent debugging this.
Want results from more Discord servers?
Add your server