i have a route problem when i run php artisan serve

Viewed 170

when i type php artisan serve i get this message :

UnexpectedValueException>Invalid route action: [App\Http\Controllers\App\Http\Livewire\HomeComponent].
at C:\xampp\htdocs\laravel8ecommerce\vendor\laravel\framework\src\Illuminate\Routing\RouteAction.php:92
     88▕      */
    89▕     protected static function makeInvokable($action)
     90▕     {
     91▕         if (! method_exists($action, '__invoke')) {
  ➜  92▕             throw new UnexpectedValueException("Invalid route action: [{$action}].");
     93▕         }
     94▕
     95▕         return $action.'@__invoke';
     96▕     }

  `App\Http\Controllers\App\Http\Livewire\HomeComponent` was not found: Controller class `App\Http\Controllers\App\Http\Livewire\HomeComponent` for one of your routes was not found. Are you sure this controller exists and is imported correctly?

  1   C:\xampp\htdocs\laravel8ecommerce\vendor\laravel\framework\src\Illuminate\Routing\RouteAction.php:47
      Illuminate\Routing\RouteAction::makeInvokable()

  2   C:\xampp\htdocs\laravel8ecommerce\vendor\laravel\framework\src\Illuminate\Routing\Route.php:191
      Illuminate\Routing\RouteAction::parse()

here is my code : web.php

<?php
use App\Http\Livewire\HomeComponent;
use Illuminate\Support\Facades\Route;



// Route::get('/', function () {
// return view('welcome');
// });

Route::get('/',HomeComponent::class);

please help im new to this

1 Answers

Check if you have protected $namespace = 'App\\Http\\Controllers'; line in App\Providers\RouteServiceProvider commented out. Ensure this line is commented out.

And second place to check is if you have defined any Route::->namespace('App\Http\Controllers')->group(function() {}); and you have defined within which this route is nested.

The error shows that router is trying to resolve a class at App\Http\Controllers\App\Http\Livewire\HomeComponent which means App\Http\Controllers is getting added before the App\Http\Livewire\HomeComponent so it must be defined either in RouteServiceProvider or in Route::group()

Related