Get other column value, filament tables
Hi. How can I get another column value in ->default() method in filament tables?
22 Replies
Is this on load from the record, or is this when a change occurs
I just want to use that as the default value of another column. how can I get that in ->default() method? should I use closure ?
fn ($record) => $record->field
this didn't work for me
you need a closure with Dennis approach, but remember default will only be used if the value is truly empty. If using fill, you will need to add it to the fill method too.
Defaults are designed for new forms
Do TableColumns even have defaults? π€
I assumed it was forms doh
Your value probably isn't
null
thenThen you need formatStateUsing()
If there isn't a method called default, I at least expected an error message and not a "didn't work"
It's now working but does this work for other methods? because I need to use $record in ->hidden() method also but to specify a condition.
Depends on the method, your IDE should show you all available methods
for example when I have something like this:
->hidden(fn ($record) => $record->factor_type === 'buy')
it thows this error: Attempt to read property "factor_type" on null. Although it works for ->default() methodI assume that is on a new form opposed to an edit, you need to check first $record is not null.
I have 3 records in this table which all of them have
factor_type
IT is saying the record is null
not the factor_type
which means the record hasn't been loaded in
Try:
fn( MyModel $record) =>
It again says it's null
Argument #1 ($record) must be of type App\Models\Factors, null given, called in
Are you creating or editing a record?
Actually it is in table builder it's not related to forms
Ugh my bad
You don't have record on a Column basis
How would you hide columns on a row level inside a table? π€
That would break the layout
Exactly, you need to format the state on the condition