Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Filament afterStateUpdated does not run for a field inside a Repeater

ErrorafterStateUpdated callback never runs for a field in a Repeater item

Short 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.

  • Applies to Filament 4, Laravel 12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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]);
    })
  2. 2Match what you see, then jump to its fix

    1. 1Nothing is logged and the form does not re-render when the field changesThe field is not liveFix
    2. 2The 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. 3The hook runs, but $get('client_id') is null$get inside the Repeater item cannot see a field outside itFix

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 item
  • A 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 | head

2Fix

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.log

Confirmed by filamentphp.com

Did this fix it?

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 | head

2Fix

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.log

Confirmed by filamentphp.com

Did this fix it?

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 | head

2Fix

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.log

Confirmed by filamentphp.com

Did this fix it?

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 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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.