Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Livewire - How to force parent component refresh?

I'd like to refresh the parent component when the child is updated.

I have a component 'base.blade.php' and in that file, there is a cart Count section. and it called in the child like this in the render function:

return view('livewire.admin-dashboard')->layout('layouts.base');

when increase and decrease the number of the products, the child component needs to Update the cart info in the base blade file. how can I do it?

best regards.

like image 505
RayanFar Avatar asked Oct 26 '25 03:10

RayanFar


2 Answers

Parent Component

protected $listeners = [
  'refreshParent' => '$refresh',
];

Child Component

public function save(){
    ... //your update code

    $this->emitUp('refreshParent');
}
like image 92
Nehal Avatar answered Oct 27 '25 18:10

Nehal


child livewire

function increment() {
    $this->emit('reRenderParent');
}

parent component

protected $listeners = ['reRenderParent'];

public function reRenderParent()
{
    $this->mount();
    $this->render();
}
like image 36
Digvijay Avatar answered Oct 27 '25 17:10

Digvijay