Filament afterStateUpdated does not run for a field inside a Repeater
afterStateUpdated callback never runs for a field in a Repeater itemShort answer
afterStateUpdated runs only after a user changes that field, and only a live field re-renders the form. A $set() call from another hook does not fire hooks unless you ask it to. Inside a Repeater, $get and $set are scoped to the current item, so use ../ to reach fields outside it.
Fix it fast
1Find out which cause you have
Put a log line in the callback. If nothing is logged when you change the field in the browser, the hook is not firing. If it logs but values are null, the problem is the field path.
->afterStateUpdated(function ($state, $old) { logger()->info('hook ran', ['state' => $state, 'old' => $old]); })2Match what you see, then jump to its fix
- 1
Nothing is logged and the form does not re-render when the field changesThe field is not liveFix - 2
The first field fires its hook, the field it fills with $set() does notThe value was set by code, not by the user, so the hook is skippedFix - 3
The hook runs, but $get('client_id') is null$get inside the Repeater item cannot see a field outside itFix
- 1
What does the error look like?
afterStateUpdated callback never runs for a field in a Repeater item$get('client_id') returns null inside a Repeater itemA field filled by $set() does not trigger its own afterStateUpdated
Cause 1 of 3
The field is not live
1Check
Filament's default is that the schema does not re-render when a user interacts with a field. live() turns re-rendering on, and the docs pair it with afterStateUpdated in their examples.
grep -rn "afterStateUpdated" app/Filament | head2Fix
Add live() to the field that owns the hook. For a text input, onBlur or a debounce cuts the number of requests.
TextInput::make('quantity')
->live(onBlur: true)
->afterStateUpdated(function (?string $state) {
// ...
})3Verify
Change the field in the browser and look for the log line.
tail -n 5 storage/logs/laravel.logConfirmed by filamentphp.com
Cause 2 of 3
The value was set by code, not by the user, so the hook is skipped
1Check
afterStateUpdated runs after a user updates a field. When another callback fills it with $set(), that field's hook is not called by default.
grep -rn "\$set(" app/Filament | head2Fix
Pass shouldCallUpdatedHooks: true to $set() for the fields whose hooks must run.
use Filament\Schemas\Components\Utilities\Set;
->afterStateUpdated(function (Set $set, ?string $state) {
$set('total', $state * 2, shouldCallUpdatedHooks: true);
})3Verify
Change the first field and confirm the second field's log line appears.
tail -n 5 storage/logs/laravel.logConfirmed by filamentphp.com
Cause 3 of 3
$get inside the Repeater item cannot see a field outside it
1Check
In a Repeater, $get() and $set() are scoped to the current item by default. A field that lives outside the Repeater needs a ../ prefix.
grep -rn "\$get(" app/Filament | head2Fix
Use ../ to climb one level out of the item. ../../ goes one level further. $get() with no argument returns the data of the current item.
use Filament\Schemas\Components\Utilities\Get;
->afterStateUpdated(function (Get $get, ?string $state) {
$clientId = $get('../client_id');
})3Verify
Change the field again and read the value in the log.
tail -n 5 storage/logs/laravel.logConfirmed by filamentphp.com
How do I stop it coming back?
- Put the hook on the field inside the Repeater schema, where the user changes the value, not on the Repeater itself.
- Use live(onBlur: true) or live(debounce: 500) on text fields instead of plain live().
- Keep one log line in new hooks until you have seen them fire once.
- Read the docs for the exact Filament major version you run.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix