16

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');
1
  • what is the error you are facing ? please add the error log here Commented Sep 13, 2020 at 7:16

4 Answers 4

36

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);
Sign up to request clarification or add additional context in comments.

4 Comments

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.
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.
in laravel 8 yield/section didn't work for me.
Although that's not related to this question, read the upgrade-manual at laravel-livewire.com/docs/2.x/upgrading
9

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);

1 Comment

Thank you stic-lab this still works on Laravel 2.5
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.

Comments

-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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.