15

I am having trouble to run my code on Laravel 8 routing with laravel-livewire.
The class is within Livewire\LandingPage.

The error I'm getting is

Attribute [livewire] does not exist

Here are my routes

<?php

use Illuminate\Support\Facades\Route;

Route::livewire('/' , 'LandingPage');

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');
Ruli
  • 2,592
  • 12
  • 30
  • 40
swatantra
  • 383
  • 1
  • 7
  • 18

4 Answers4

35

If you are using a recent install of Laravel 8, you will have Livewire V2. In this version, Route::livewire()has been removed. Instead, you specify a normal get() route, with the action being the Livewire component class.

Route::get('/' , App\Http\Livewire\LandingPage::class);
Qirel
  • 25,449
  • 7
  • 45
  • 62
  • 6
    Another perfectly good question closed on SO... remember to swap `@yield('content')` with `{{ $slot }}` in your `app.blade.php` also for the conversion to V2. – sorrell Oct 21 '20 at 17:57
  • Aye, its not a question that should have been closed. I have asked to reopen it. That said, you can use either the `yield`/`section` as before, or slots. Depends if you are using partials or components; they're different things to achieve the same goal. – Qirel Oct 21 '20 at 18:07
  • 1
    in laravel 8 yield/section didn't work for me. – mbouzahir Dec 19 '20 at 19:36
  • 1
    Although that's not related to this question, read the upgrade-manual at https://laravel-livewire.com/docs/2.x/upgrading – Qirel Dec 19 '20 at 20:25
8

If you use livewire v1.x please use this annotation :

//(livewire v1.x)
Route::livewire('/post', 'LandingPage');

If you are using livewire v2.0 please use this one :

//(livewire v2.x)
Route::get('/post', \App\Http\Livewire\LandingPage::class);
stic-lab
  • 433
  • 7
  • 16
0

From the error it appears you do not have the auth system setup:

Route::group(['middleware' => 'auth'], function () {
    // Only with LiveWire v1
    //Route::livewire('/blog', 'blog')->section('blog');

    // For LiveWire 2.
    Route::get('/blog' , 'BlogController@index');
});

You are calling the auth middleware and the error is stating there is no LoginController presently located in Auth\LoginController

Do you have any auth scaffolding setup?

Didn't realize this was such an old thread.

Ray C
  • 164
  • 8
-2

With Laravel 8.29 and LiveWire 2.4.0

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

I think that is better tha you need create a new Controller in App\Http\Controllers and link the route with this Controller. In the view use @liveware to your LiveWire Controller.

Route::group(['middleware' => 'auth'], function () {
    // Only with LiveWire v1
    //Route::livewire('/blog', 'blog')->section('blog');

    // For LiveWire 2.
    Route::get('/blog' , 'BlogController@index');
});

App\Http\Controllers\BlogController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BlogController extends Controller
{
    public function index(){
        return view('blog.index');
    }
}

resources/views/blog/index.blade.php

@livewire('blog')

Note: With the fix (https://laravel-livewire.com/docs/2.x/upgrading)

protected function mapWebRoutes()
{
    Route::middleware('web')
        ->namespace($this->namespace) // Remove me
        ->group(base_path('routes/web.php'));
}

you will have problems with routes in Middlewares

Illuminate\Contracts\Container\BindingResolutionException Target class [Auth\LoginController] does not exist.

Juan
  • 1
  • 1