© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
46 replies
Eric

How to access form component record in ->when fn?

with this code:
Forms\Components\DateTimePicker::make('paid_at')
    ->label(__('Paid at'))
    ->disabled()
    ->when(
        value: function (Forms\Components\DateTimePicker $dateTimePicker, Payment $record): bool {
            return $record->has_users;
        },
        callback: function (Forms\Components\DateTimePicker $dateTimePicker): Forms\Components\DateTimePicker {
            return $dateTimePicker
                ->hint(function (Payment $record): ?string {
                    if (is_null($record->paid_by_id)) {
                        return null;
                    }

                    return "{$record->paid_at->diffForHumans()}";
                })
                ->hintIcon('heroicon-s-question-mark-circle')
                ->hintIconTooltip(function (Payment $record): ?string {
                    if (is_null($record->paid_by_id)) {
                        return null;
                    }

                    return __('Paid by') . " {$record->paidBy->getFullname()} ({$record->paidBy->email}), {$record->paid_at->diffForHumans()}";
                })
            ;
        },
        default: function (Forms\Components\DateTimePicker $dateTimePicker): Forms\Components\DateTimePicker {
            return $dateTimePicker
                ->hint('false') // ⚠️ todo
            ;
        }
    )
,
Forms\Components\DateTimePicker::make('paid_at')
    ->label(__('Paid at'))
    ->disabled()
    ->when(
        value: function (Forms\Components\DateTimePicker $dateTimePicker, Payment $record): bool {
            return $record->has_users;
        },
        callback: function (Forms\Components\DateTimePicker $dateTimePicker): Forms\Components\DateTimePicker {
            return $dateTimePicker
                ->hint(function (Payment $record): ?string {
                    if (is_null($record->paid_by_id)) {
                        return null;
                    }

                    return "{$record->paid_at->diffForHumans()}";
                })
                ->hintIcon('heroicon-s-question-mark-circle')
                ->hintIconTooltip(function (Payment $record): ?string {
                    if (is_null($record->paid_by_id)) {
                        return null;
                    }

                    return __('Paid by') . " {$record->paidBy->getFullname()} ({$record->paidBy->email}), {$record->paid_at->diffForHumans()}";
                })
            ;
        },
        default: function (Forms\Components\DateTimePicker $dateTimePicker): Forms\Components\DateTimePicker {
            return $dateTimePicker
                ->hint('false') // ⚠️ todo
            ;
        }
    )
,


i get:
Too few arguments to function App\Filament\Resources\PaymentResource::App\Filament\Resources\{closure}(), 1 passed in /Users/eric/Documents/projects/suite_bg_wrapper/bgpay/vendor/laravel/framework/src/Illuminate/Conditionable/Traits/Conditionable.php on line 23 and exactly 2 expected
Too few arguments to function App\Filament\Resources\PaymentResource::App\Filament\Resources\{closure}(), 1 passed in /Users/eric/Documents/projects/suite_bg_wrapper/bgpay/vendor/laravel/framework/src/Illuminate/Conditionable/Traits/Conditionable.php on line 23 and exactly 2 expected

the error line is this one:
value: function (Forms\Components\DateTimePicker $dateTimePicker, Payment $record): bool {
value: function (Forms\Components\DateTimePicker $dateTimePicker, Payment $record): bool {


the objective is to show hints "A" or hints "B" depending if the
has_users
has_users
record field is true or not
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to get record in `columns` fn
FilamentFFilament / ❓┊help
3y ago
Access record in form method
FilamentFFilament / ❓┊help
3y ago
How to access form state in Custom Livewire component
FilamentFFilament / ❓┊help
5mo ago
How to access record in infolist
FilamentFFilament / ❓┊help
2y ago