Search code examples
phplaravelpushlaravel-livewire

Laravel Livewire - how to get @push to work?


Not sure what I'm missing here, but nothing I do seems to allow @push('styles') or @push ('scripts') to work.

layout/app.blade.php includes:

...

 @livewireStyles

...

 @livewireScripts

...

livewire/tagify.blade.php

@push('styles')
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@yaireo/[email protected]/dist/tagify.min.css">


@endpush

@push('scripts')
  <script src="https://cdn.jsdelivr.net/npm/@yaireo/[email protected]/dist/tagify.min.js"></script>
  <script>
  document.addEventListener("DOMContentLoaded", function(event) {

    var input = document.getElementById('tagify')
    var tagify = new Tagify(input, {
      whitelist : [
        @foreach($tags as $tag)
          '{{ $tag }}'@if(! $loop->last), @endif
        @endforeach
      ]
    })
    input.addEventListener('change', onChange)

    function onChange(e){
      @this.call('changeTags', e.target.value)
    }

  })
  </script>

@endpush

The rest of the component is included fine.


Solution

  • Nevermind,

    turns out layout/app.blade.php seems to also need

    @stack('scripts')
    

    and

    @stack('styles') 
    

    for @push to work.