mhmiton / laravel-modules-livewire

Using Laravel Livewire in Laravel Modules package with automatically registered livewire components for every modules.
MIT License
179 stars 33 forks source link

Error when using slots in Laravel modules Livewire components #25

Closed DanielRondonGarcia closed 1 year ago

DanielRondonGarcia commented 1 year ago

I'm trying to use slots in a Livewire component inside a Laravel module, but it's giving me the following error:

ErrorException
Undefined variable $slot (View: C:\wamp64\www\laravel\Modules\User\Resources\views\livewire\test.blade.php)

The component code is as follows:

<div>
    <h3>The <code>{{ $slot }}</code> livewire component is loaded from the <code>{{ $options }}</code> module.</h3>
</div>

And in the view I am using the component as follows:

<livewire:user::test>
    @slot('slot')
        Test
    @endslot
    @slot('options')
        User
    @endslot
</livewire:user::test>

Has anyone had a similar problem or knows how to fix it?

mhmiton commented 1 year ago

@DanielRondonGarcia Maybe the livewire component doesn't support the slot things. So, you can use props instead of slots. Please, check these resources.

Add component slots - https://github.com/livewire/livewire/issues/68

Slots in Livewire - https://github.com/livewire/livewire/issues/941

titonova commented 11 months ago

Created a very simple package that does that: https://github.com/titonova/x-livewire

You can now do

<x-livewire _="alert">
  Alert message
</x-livewire>