Using class instead of alias for Single Page Component routes

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?

I don’t see a downside. There is a built in way to register components in a service provider already if you don’t want to have the additional logic. How To Integrate Livewire in Package?

@xxdalexx thanks for the reply. I know about the possibility to register components, but this is what I try to avoid - to have to register every component.

I am more concerned that my code has side effects because it is not resolving the component using the manifest.