F
Filamentβ€’5mo ago
dyo

Using global variable in form input method at resource class

How can I use like a global variable in form input method at resource class? Here's my case:
TextInput::make('jumlah')
->prefixIcon(
function ($record) {
if ($record->retur_vendor_detail->sum('jumlah') != $record->jumlah) {
return 'heroicon-o-exclamation-triangle';
}

return null;
}
)
->prefixIconColor('danger')
->helperText(function ($record) {
if ($record->retur_vendor_detail->sum('jumlah') != $record->jumlah) {
return '* Jumlah tidak sesuai dengan data retur vendor detail.';
}

return null;
}),
TextInput::make('jumlah')
->prefixIcon(
function ($record) {
if ($record->retur_vendor_detail->sum('jumlah') != $record->jumlah) {
return 'heroicon-o-exclamation-triangle';
}

return null;
}
)
->prefixIconColor('danger')
->helperText(function ($record) {
if ($record->retur_vendor_detail->sum('jumlah') != $record->jumlah) {
return '* Jumlah tidak sesuai dengan data retur vendor detail.';
}

return null;
}),
I want $record->retur_vendor_detail->sum('jumlah') to be called only once.
Solution:
Yes. $this->record->loadSum('retur_vendor_detail') and then use $this->record->retur_vendor_detail_sum
Jump to solution
5 Replies
dyo
dyoOPβ€’5mo ago
can someone help me?
Dennis Koch
Dennis Kochβ€’5mo ago
$record is not a global variable. It's injected by Filament. Is this really only form builder or in a Panel? Ideally you eager-load that data on mount
dyo
dyoOPβ€’5mo ago
yeah that's only in form builder.. so i need to load both in create and edit record page mount?
Solution
Dennis Koch
Dennis Kochβ€’5mo ago
Yes. $this->record->loadSum('retur_vendor_detail') and then use $this->record->retur_vendor_detail_sum
dyo
dyoOPβ€’5mo ago
thanks for your help.. πŸ‘
Want results from more Discord servers?
Add your server