Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Respect's avatar

how to listen globally to livewire updating hook from AppServiceProvider.php in livewire 4

how to listen globally to livewire updating hook from AppServiceProvider.php in boot method

  • Does not work
        \Livewire\Livewire::listen('component.updating', function ($component) {
            // This will now catch the internal "Livewire\Generated\Component..." classes
            throw new \Exception('Global Boot Caught SFC: ' );
        });
1 like
15 replies
Respect's avatar

first thnaks for answer i am using livewire 4

imrandevbd's avatar

Assuming you're on v3, Livewire::listen is for events, not lifecycle hooks. You need to use Livewire::hook.

For global property updates, you should hook into commit:

use Livewire\Livewire;

public function boot(): void
{
    Livewire::hook('commit', function ($component, $commit) {
        // You can inspect $commit->updates for specific property changes.
    });
}

If you specifically need to run logic before the component finishes its cycle, commit is the standard way to intercept that in v3.

1 like
vincent15000's avatar

It seems to have been possible with version 2, I don't have tested if it's still available with version 3, but sure in versions 3 and 4, it doesn't appear in the documentation.

Respect's avatar

thanks for answer but did not working in livewire v 4 got error

Error
vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:363
Call to undefined method Livewire\LivewireManager::hook()

LARAVEL
13.3.0
PHP
8.3.30
UNHANDLED
CODE 0
500
GET
http://127.0.0.1:8000/admin/order/create

Exception trace
1 vendor frame

Illuminate\Support\Facades\Facade::__callStatic()
app/Providers/AppServiceProvider.php:34

29        
34        Livewire::hook('commit', function ($component, $commit) {
35            dd('Hello from app ServiceProvider');
36            // You can inspect $commit->updates for specific property changes.
37        });
38    }
39}


  • full code
<?php
use Livewire\Livewire;

    public function boot(): void
    {

        Livewire::hook('commit', function ($component, $commit) {
            dd('Hello from app ServiceProvider');
            // You can inspect $commit->updates for specific property changes.
        });
    }
1 like
Jsanwo64's avatar

why not create your own base component and extend it everywhere

1 like
Respect's avatar

thanks for answer - i wanna share my knowlage may helping some one i need listen to it globally because i am trying to create a composer livewire package almost done the logic 97% that will secure properies by default because livewire-strict does not working any more for livewire 4 single file component --sfc so the only step left how to listen globally so that i need listen globally if i did not find a way - i think i have to reformat it as normal code and ppl use a BaseComponent extends or Trait or something - i hope can find a way to make it a package

1 like
Jsanwo64's avatar

Because i dont think you can globally listen to updating from AppServiceProvider in PHP in Livewire 4 using

Livewire::listen()

or

Livewire::hook()
1 like
Respect's avatar

thanks for answer but both of them did not work

1 like
ghabriel25's avatar

The questions are

  • why would you need it inside service provider?
  • any context about what you're trying to achieve?

With those answered, I'm pretty sure someone can help you.

1 like
Respect's avatar

Thanks for answer i wanna share my knowlage may helping some one i need listen to it globally because i am trying to create a composer livewire package almost done the logic 97% that will secure properies by default because livewire-strict does not working any more for livewire 4 single file component --sfc so the only step left how to listen globally so that i need listen globally

1 like
Respect's avatar

thanks for answer i tried custom class before not working something like

        Livewire::componentHook(PropertySecurityHook::class);

i think the main point now global hook or listener for editing more then a month iam working in this package .. it's possible in livewire 3 global listener . but in liveiwre 4 did not working - i will trying search for more ideas . the main point realted to livewire v4

ghabriel25's avatar

This

public function register()
{
    app('livewire')->componentHook(PropertySecurityHook::class);
}

I have been using custom class as component hook since L4 launch and it works as expected

Please or to participate in this conversation.