F
Filament13mo ago
daar

Hide SelectColumn based on soft delete status

I want to hide a column, as per the title. See the code below. This has worked before within the project, but I in this case get the error: Argument #1 ($record) must be of type App\Models\Payment, null given. Any suggestions?
Tables\Columns\SelectColumn::make('payment_method')
->visible(fn (Payment $record) => $record->deleted_at),
Tables\Columns\SelectColumn::make('payment_method')
->visible(fn (Payment $record) => $record->deleted_at),
9 Replies
krekas
krekas13mo ago
payment_method is null for some records either don't allow null values or if it's null set to true/false
daar
daarOP13mo ago
@krekas thanks for your reply! Here's the definition for the field: $table->tinyInteger('payment_method')->default(0);. So it has always a value as per definition.
krekas
krekas13mo ago
My bad. Not the payment_method but the model itself in your error
daar
daarOP13mo ago
@krekas , this code is for a column on a list view. How can the model be null? Ith view shows all existing records
krekas
krekas13mo ago
Try dumping
daar
daarOP13mo ago
The fail comes already on the function parameter. So the following also fails: fn (Payment $record) => true)
Patrick
Patrick13mo ago
Tables\Columns\SelectColumn::make('payment_method')
->visible(fn (?Payment $record) => $record?->deleted_at === null);
Tables\Columns\SelectColumn::make('payment_method')
->visible(fn (?Payment $record) => $record?->deleted_at === null);
doesn't this work?
krekas
krekas13mo ago
But it's a table. Record should always be. Remove the type hint
daar
daarOP13mo ago
Exactly. The strange thing is, I have used it before but it fails on this particular table. This is previous code: ->visible(fn (CashbookInvoice $record) => $record->deleted_at),. This was on an action, not on a Column class. The closure on the visible method does not accept the variable I have defined. This works perfectly well :
->getStateUsing(function (Payment $record): float {
return $record->payment_method + 1;
}),
->getStateUsing(function (Payment $record): float {
return $record->payment_method + 1;
}),
with the visible method the following closure is expected: Closure $condition = true while with getStateUsing the closure is a callback

Did you find this page helpful?