laravellaravel-8laravel-livewirelivewires

laravel - livewire Full-Page Components


I use laravel 8.

I define protected namespace in RouteServiceProvider:

protected $namespace = 'App\Http\Controllers';

then use livewire with the below route:

Route::get('/xxx' , App\Http\Livewire\Counter::class);

but I have the below error :

Invalid route action: [App\Http\Controllers\App\Http\Livewire\Counter].

Notice: this adds App\Http\Controllers first of my action !!! if remove protected $namespace all is OK. But I do not want to delete it.

Is there a way for me to have both ‍controller protected namespace (for controller namespace) and a Route::get for Full-Page Components?


Solution

  • Unfortunately, you won't be able to use protected $namespace together with Livewire. You'll have to comment it back out and update all your routes to the laravel 8 way: https://laravel.com/docs/8.x/releases#routing-namespace-updates

    Because livewire components don't live under App\Http\Controllers, using $namespace will never work.

    As far as I understand it. Route::livewire existed in Livewire 1.x because of this issue in Laravel 7. But with Laravel 8 it could be removed in favor of the new way.