I am learning Laravel 9, and I got a problem Target class [AdminDashboardController] does not exist.
when using prefix routing. Is someone can help me to fix it?
this code on routes/web:
Route::prefix('admin')->namespace('Admin')->group(function(){
Route::get('/','DashboardController@index')->name('dashboard');
});
this code on AppHttpControllersAdminDashboardController:
namespace AppHttpControllersAdmin;
use AppHttpControllersController;
use IlluminateHttpRequest;
class DashboardController extends Controller
{
public function index(Request $request){
return view('pages.admin.dashboard');
}
}
2
Answers
You’ve specified an incorrect
namespace
in yourroute
. As per the error message:Laravel expects to find a
DashboardController
in theAdmin
namespace
, however, you’ve defined yourDashboardController
with thenamespace AppHttpControllersAdmin
.Update the
namespace
on your route.If you read the documentation, you will see that you must use another way: