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?
9 Replies
payment_method
is null for some records
either don't allow null values or if it's null set to true/false@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.My bad. Not the payment_method but the model itself in your error
@krekas , this code is for a column on a list view. How can the model be null? Ith view shows all existing records
Try dumping
The fail comes already on the function parameter. So the following also fails:
fn (Payment $record) => true)
doesn't this work?
But it's a table. Record should always be. Remove the type hint
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 :
with the visible
method the following closure is expected: Closure $condition = true
while with getStateUsing
the closure is a callback