Because I have components in multiple namespaces and use Single Page Components whenever possible, I was looking for a way to register those components using the class name.
So instead of Route::livewire('/login', 'login')
this, I wanted this this Route::livewire('/login', \App\Domain\Auth\Components\Login::class)
.
It turned out it was pretty simple to get it working. In a service provider I have this:
public function register()
{
Livewire::componentResolver(function ($classOrAlias) {
if (class_exists($classOrAlias)) {
$this->app->get('livewire')->component($classOrAlias, $classOrAlias);
return $classOrAlias;
}
return str_replace(
['.', '-'],
['\\', ''],
ucwords($classOrAlias, '.-')
);
});
}
What could (or is) the downside of resolving the components like this?