How To Integrate Livewire in Package?

I have a package that I would like to convert from JavaScript/Vue to Livewire. My goal is to have the package manage all the Livewire components without the user having to take extra action: I would like to set up the entire Livewire ecosystem for my package in my package’s service provider. Is this possible?

I’ll take a stab since nobody else has. I think everything would be fine as long as all your name spacing and package discovery is in order. You might run into problems, or just need extra configuration if you’re going to allow the livewire components to be published.

But I could be wrong, this is just an educated guess. I have a basic understanding of packages and laravel specific packages, but I’ve never actually done one myself.

Hi @xxdalexx, thanks for taking the time to respond. I have gotten almost everything figured out, with exception of the detection of Livewire Component classes due to the class_namespace config setting being set to the main app namespace (which shouldn’t be changed). For now I am working around this by publishing the component classes to the main app, but preferably this wouldn’t be necessary.

@calebporzio would it be possible to add multiple namespaces to the configuration setting, so that the Livewire classes could live inside my package, and not interfere with the developer’s Livewire classes in the main app?

Hey @mikebronner, you can register components in a service provider like so:

Livewire::component('your-package::your-component', YourComponent::class);

Does that solve your problem?

1 Like

Thanks @calebporzio, I’ll give that a shot and report back. :slight_smile:

Update: worked like a treat! brilliant. :slight_smile: