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

Scop's avatar
Level 1

How to Auto-Refresh Livewire Component B When Component A Updates Data in Livewire V3

i have to components in one single page...

this is component CompA.php

public function requestToApprove() {

    $checktheApprovalrequestTbl = DB::table('temp__items')->count();
    $numberOfRequestedItems = DB::table('temp__items')->where('ask_to_approval','hold')->count();
    $requstedAllItems = DB::table('temp__items')->where('ask_to_approval','hold')->get();
    $requstedUserName = Auth::user()->user_name;
    $AllSuperAdmins = DB::table('sysusers')->where('user_role','Super Admin')->get();
    $requestUserRole = Auth::user()->user_role;


    if ($checktheApprovalrequestTbl === 0) {
        return session()->flash('approvalRequestError', 'Error: The operation cannot proceed because the table is empty.');
    } else {

        DB::table('temp__items')->update(['ask_to_approval' => 'pending']);

       foreach($AllSuperAdmins as $admin)
       {
        Mail::to($admin->user_email)->send(new requestToApproveItem($requestUserRole,$numberOfRequestedItems,$requstedUserName,$requstedAllItems));
       }

      $catchNotify = ItemRequestNotification::create([
        'user_email' => Auth::user()->user_email,
        'user_name' => Auth::user()->user_name,
        'pending_items' => $numberOfRequestedItems,
        'notification_message' => 'New Items pending for Approvals',
        'notification_type' => 'Pending for Approvals Notification',
       ]);

       

        return session()->flash('approvalRequest', 'Inventory List Successfully Sended for Approval');
    }
}

this is compB.php

public function PendingItemsNotify() { $this->notMarkedNotifications = DB::table('item_request_notifications')->where('notification_status', 'not marked')->count();

}

public function render() { $this->PendingItemsNotify(); }

when compA method worked in that same time compB want to refresh, count value automaticly want to update.

how to do that?

NOTE: -> iam using livewire V3 -> $this->emit() not support to V3

0 likes
4 replies
vincent15000's avatar

You can for example set an event / listener.

Here is the documentation where you will find how to dispatch an event.

https://livewire.laravel.com/docs/events#dispatching-events

$this->dispatch('post-created'); 

And here how to listen to an event.

https://livewire.laravel.com/docs/events#listening-for-events

And I think that in Livewire 3 you can still use the old way to listen to events.

protected $listeners = ['monEvenement' => '$refresh'];

Which could let you refresh the component.

1 like
Scop's avatar
Level 1

@vincent15000 thanks for your reply

i already try this, not working

compA.php

$this->dispatch('requested-Notify-Triggered');

compB.php

protected $listeners = ['requested-Notify-Triggered' => '$refresh'];

public function PendingItemsNotify()
{
      $this->notMarkedNotifications =  DB::table('item_request_notifications')->where('notification_status', 'not marked')->count();

}

idk, its not working

let me explain my problem with scenario

when user click request btn, that function store as notification (compA)

$catchNotify = ItemRequestNotification::create([ 'user_email' => Auth::user()->user_email, 'user_name' => Auth::user()->user_name, 'pending_items' => $numberOfRequestedItems, 'notification_message' => 'New Items pending for Approvals', 'notification_type' => 'Pending for Approvals Notification', ]);

in compB i fetching the notifications

public function PendingItemsNotify() { $this->notMarkedNotifications = DB::table('item_request_notifications')->where('notification_status', 'not marked')->count();

}

public function render() {

    $this->PendingItemsNotify();}

at the same time this is want to update

like, facebook. if someone send like or cmnt our post, at the same time we gotta notification.

and one more thing, wire:poll also i try to do that, but that thing affect my js and other livewire functions

any other solutions?

1 like
mkajjui's avatar

It's important that we get notified whenever someone likes or comments on our posts. run 3

1 like

Please or to participate in this conversation.