© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
Kiran Timsina

How to run a query based on fields and show output in another field

This is my form :

return $form
->schema([
Group::make([
Toggle::make('has_verified_email')->reactive(),
Toggle::make('has_verified_phone')->reactive(),
Toggle::make('new_users_only')->reactive()
->afterStateUpdated(fn (Closure $set, $get, $state) => $get('new_users_only') ? $set('old_users_only', !$state) : ''),
Toggle::make('old_users_only')->reactive()
->afterStateUpdated(fn (Closure $set, $get, $state) => $get('old_users_only') ? $set('new_users_only', !$state) : ''),
Forms\Components\TextInput::make('test')->afterStateUpdated(
function (Closure $get) {
$count = User::when($get('has_verified_email'), function ($q) {
$q->whereNotNull('email_verified_at');
})->when($get('has_verified_phone'), function ($q) {
$q->whereNotNull('has_verified_phone');
})->when($get('new_users_only'), function ($q) {
$q->whereDate('created_at', '>=', now()->subMonth());
})->when($get('old_users_only'), function ($q) {
$q->whereDate('created_at', '<=', now()->subMonth());
})->count();
return "$count users selected!";
}
)
->columnSpanFull()->disabled()->disableLabel()
])->columnSpan(12)->columns(4),

I want to fill up the field 'test' with the count of users based on the other toggles set. I could set it using default but it works in first load only. I want to update the 'test' every time a toggle is changed.

Is there a way to achieve this? Thank You
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

Show a list of options based on another field
FilamentFFilament / ❓┊help
2y ago
how to display fields of form based on value of another field?
FilamentFFilament / ❓┊help
2y ago
Show/Hide fields based on selection
FilamentFFilament / ❓┊help
3y ago
How to modify "Create Another" action in Filament to include a query parameter based on a form field
FilamentFFilament / ❓┊help
10mo ago