Route::livewire cause error

What seems to be the problem:
When added livewire route I get this error all the time:

InvalidArgumentException    

Attribute [livewire] does not exist.

          at vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:92
             88▕      */
             89▕     public function attribute($key, $value)
             90▕     {
             91▕         if (! in_array($key, $this->allowedAttributes)) {
          ➜  92▕             throw new InvalidArgumentException("Attribute [{$key}] does not exist.");
             93▕         }
             94▕
             95▕         $this->attributes[Arr::get($this->aliases, $key, $key)] = $value;
             96▕

          3   routes/web.php:5
              Illuminate\Support\Facades\Facade::__callStatic("livewire")

          8   app/Providers/RouteServiceProvider.php:104
              Illuminate\Routing\RouteRegistrar::group("/Users/xxx/code/laravelhub/routes/web.php")

Steps to Reproduce:
I just create livewire component and add to routes/web.php simple route:
Route::livewire('threads', Threads::class);
And it doesn’t matter if this route is as single line or inside some route groups with a set of middlewares.
In routes/web.php I have:
use Illuminate\Support\Facades\Route;

Are you using the latest version of Livewire:
Livewire 2.0.0
Laravel 7

Hey @qrczak,

the “livewire” method is not available anymore in V2.

Simply use “get” with the FQCN:

Route::get('/post', \App\Http\Livewire\ShowPosts::class);

Thank you very much. Now works!
But in the documentation (v.2), under " Rendering Components" there are still
Route::livewire
that’s why I was confusing.

Hey @maxeckel,

Please update documentation on this, i really spent about half day looking to how to fix this. Please mention this in documentation because Laravel 8 is not out yet.

Regards.

@macgadger Sorry but how Laravel 8 is related to this problem?

Hey @qrczak,

you are welcome :wink:

Hey @macgadger,

it is clearly stated in the upgrade guide that the old “livewire” method has been removed and it shows how the routes should be defined in V2:

// Before
Route::livewire('/post', 'show-posts');

// After
Route::get('/post', \App\Http\Livewire\ShowPosts::class);  

Also, this is not related to Laravel 8, but you will need to clear or remove the $namespace definition of your RouteServiceProvider, otherwise the namespace will probably be wrong.

But you are right, in the normal Docs (outside of the Upgrade Guide) there are still code snippets using the old way. I’ll create a pull request for the Docs if no one else already did that.

Edit: The old references have already been fixed a few hours ago in the Docs repo, seems like it isn’t deployed yet.

Happy coding! :wink:

1 Like

Hi @maxeckel

Removing the namespace definition in RouteServiceProvider doesn’t work for my controller based routes and leaving the namespace in there doesn’t work for Livewire routes.

I ended up doing this, but any other suggestions?

  Route::get('/new-quote/companies/',
        [\App\Http\Livewire\NewQuoteCompanyTable::class, '__invoke']
    );
2 Likes

Hey @ryatkins,

i guess this is the only way to do this in your case, or you have to update all your normal controller routes to use FQCN and not simply strings.

This was helpful,
Did try the spa mode?
How did you resolve the turbolinks issue?.

Hey @moneya,

what do you mean by “turbolinks issue”? Turbolinks support has been removed from V2, but you can bring it back if needed:

1 Like

Solved it , thanks @maxeckel

@maxeckel Does this mean turbolinks and SPA in general is discouraged in Livewire?

Btw for controller routes, if you remove the $namespace in Route Service Provider in order to use Livewire routes you can still include regular controller routes like so:

Route::get(’/test’, [TestController::class, ‘index’]);

Which is going to call the TestController@index method for this route.

Hey @ilianandreev,

using Turbolinks is not discouraged, but the support has been removed from the Core as it is not really in it’s the scope to enable this. That’s why it is now available as a “Plugin”. Also I think the term SPA is not really appropriate when using Livewire/Turbolinks.

Yes the tuple syntax works perfectly fine. You can also use the string syntax, if you use the FQCN or group the routes within a namespace call.