Target Class [UserController] does not exist on Laravel



How to fix Target Class [UserController] does not exist on Laravel 8.*

For the first you can check your Laravel Version at Command Prompt.

1. You can type php artisan --version.


2. Go to RouteServiceProvider.php and edit :


/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/

public function boot()
{
$this->configureRateLimiting();

$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));

Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}

3. And next go to your controller and edit class :

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class DashboardController extends Controller
{
//
public function index(request $request)
{
return view('pages.dashboard');
}
}

4. For the last intruction you can check and edit web.php :

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

Route::prefix('admin')
->namespace('Admin')
->group(function()
{
Route::get('/','DashboardController@index')
->name('dashboard');
});


FIX.

Post a Comment

0 Comments