1

im still new to laravel 8 and i have a problem that says the target class does not exist. i believe it have something with the route of some sorts(?) im not sure. i only follow the tutorial but this is the error that i get. this is what i wrote,

web.php:

<?php

use Illuminate\Support\Facades\Route;


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



Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::group(['middleware' => ['auth', 'admin']], function () {

    Route::get('/dashboard', function () {
        return view('admin.dashboard');
    });
    
    Route::get('/role-register','Admin\DashboardController@registered');
});
harraz syah
  • 45
  • 1
  • 7
  • 2
    Does this answer your question? [Target class controller does not exist - Laravel 8](https://stackoverflow.com/questions/63807930/target-class-controller-does-not-exist-laravel-8) – matiaslauriti Jul 04 '21 at 20:54

3 Answers3

2
  1. Ensure the class App\Http\Controllers\Admin\DashboardController exists at the correct location with the correct namespace at the top of the file. This should be in app/Http/Controllers/Admin/ with the namespace App\Http\Controllers\Admin.
  2. For consistency, use [App\Http\Controllers\Admin\DashboardController::class, 'registered'] instead of 'Admin\DashboardController@registered' when referencing the controller method. You might want to name this route too.
brice
  • 1,801
  • 1
  • 10
  • 15
  • tried this and it works. apparently laravel 8 doesnt recognize the old ways, but by using this, it can run normally. thank you :) – harraz syah Jul 05 '21 at 15:36
2

Try using the following.

Route::get('/role-register', 
    [App\Http\Controllers\Admin\DashboardController::class, 'registered']);

Instead of:

Route::get('/role-register', 'Admin\DashboardController@registered');
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
0

Use the correct namespace i.e

'namespace'=>'App\Http\Controllers\Admin' instead of 'namespace'=>'Admin'.
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175