Is there a way to alias a component that's not in the App\Http\Livewire namespace?

The structure of my project is a bit different where the components are not in the App\Http\Livewire namespace so i’m having to do <livewire:App\Domains\My\Other\Component::class> and it’s really ugly looking. Is there a way to alias the component namespace to the name so I can continue to use <livewire:my-component>?

Did you publish the config? You should be able to modify there.

Yeah it looks like there can only be one namespace. Basically by design I would have the components organized in different areas of the project files, but it looks like that have to be in one directory correct? So i’ll just leave them all in App/Http/Livewire.

There’s probably much better way than this…

The manifest is stored \bootstrap\cache\livewire-components.php that I think you could overwrite. If I’m not wrong on that, the headache of this is every time you create a new component or run livewire:discover, that file is going to be overwritten and you will have to change it again.

Hi,

@Rappasoft is right it’s not obvious to change this when you have structured your app by Modules for instance.
We have this package which explains how we could do. I try on a Module (package Nwidart without success)

If you have a solution :wink:

There is a way of doing this, at a cost.

I totally believe that I should not have to have all of my Livewire related components in one directory. As an example, I have an app which has multiple modules contained within in. Short of having a repeated directory structure all over the shop, I want to follow DDD.

So, how to do this? In the livewire configuration, just blank the class namespace value. Leave it empty.

The cost here is that the CLI commands for livewire will no longer work, except the discover method. The only downside here is that when the discover method runs, it is performing reflection checks against every class in your app directory… now one could say that’s inefficient, but one would argue that it’s compiled pre-production ¯_(ツ)_/¯

I think this certainly needs an improvement, but this is what I’ve found to work. I had an issue where I wanted to set the class namespace to App\, but then when it compiled the manifest it cut off the first letter of the key in the manifest… annoyingly it’s because when the discover’s build function runs, it’s adding an extra \ in front of the namespace path in reflection.