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

Chaeril's avatar

@push inside child does not run

i have 1 parent that tracks state from each child @livewire('booth', ['user' => $user]) inside it i have multiple child with switch,

  @switch($state)
    @case('st')
      @livewire('booth.start')
    @break

    @case('nd')
      @livewire('booth.second', ['user' => $user])
    @break

    @case('rd')
      @livewire('booth.third', ['user' => $user])
    @break

    @case('th')
      @livewire('booth.forth', ['user' => $user])
    @break

    @default
  @endswitch

it will run and change based sequentially, i use dispatch to change the state. but the only @push that getting pushed is first. the other did not push any javascript.

what is the right way to do this. thanks

1 like
3 replies
vincent15000's avatar

I don't see any @push in your code.

Instead of using switch ... case ... you should better use dynamic livewire component.

You could rename the states to start, second, third, ... instead of st, nd, ...

<livewire:dynamic-component :is="'booth.'.$state"></<livewire:dynamic-component>

Or use a key value array.

@php
		$states = [
				'st' => 'start',
				'nd' => 'second',
				...
		];
@endphp

<livewire:dynamic-component :is="'booth.'.$states[$state]"></<livewire:dynamic-component>
1 like
Chaeril's avatar

its on the layout

...
    {{ $slot }}
  </div>

  @livewireScripts
  @stack('scripts')

in the end i append all of the scripts inside booth.blade.php just under the switch case and it works.


...


    @default
  @endswitch
</div>

@push('scripts')
  <script>
    console.log("Script inside start loaded!");
    Livewire.on('start-booth', ({
      postId
    }) => {
      console.log("Start both event received!");
    });

...

1 like
vincent15000's avatar

@Chaeril

With a similar situation, I had problem without a dynamic component.

So you should really use a dynamic component, especially if you need to switch from one state to another.

Please or to participate in this conversation.