Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rikarsen's avatar

ReflectionException Class App\Http\Controllers\Admin\AdminController does not exist

I am using laravel 5. My AdminController looks like that:

<?php namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;

class AdminController extends Controller {

    ...

    public function index()
    {
        return view('admin.index');
    }
}

My routes look like that:

<?php

...

Route::group(array('prefix' => 'admin'), function()
{
    Route::get('/', 'Admin\AdminController@index');
});

My file path looks like that:

app/Http/Controllers/Admin/AdminController.php

However, I get the following exception when I open the public folder of my application:

ReflectionException in Container.php line 776:
Class App\Http\Controllers\Admin\AdminController does not exist

Any suggestions why the controller cannot be found?

0 likes
7 replies
bestmomo's avatar

There is a base namespace in RouteServiceProvider :

protected $namespace = 'App\Http\Controllers';

So if you want to have custom namespace you should change it or delete it :

protected $namespace = '';
1 like
RachidLaasri's avatar
Level 41

The problem is in here, Your class in is 'App\Http\Controllers\Admin\AdminController'

But you set your namespace to 'App\Http\Controllers\Auth'

change it to '''App\Http\Controllers\Admin"

<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

class AdminController extends Controller {

    public function index()
    {
        return view('admin.index');
    }
}
9 likes
RachidLaasri's avatar

One more thing, i guess you are building an admin idea, so you'll need to set all of your routes to "Admin\Controllername@method", i suggest using the namespace option.

Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function()
{
    Route::get('/', 'AdminController@index');
});
2 likes
sanjay23's avatar

Hello Friends,

I am also facing the same problem,

My controller file as follow. namespace App\Http\Controllers\admin; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Http\Request;

class adminController extends Controller { }

Help would be appreciable

QRLSystems's avatar

You can also encounter this error for a very simple reason - bad coding in the Controller. To check if this is the case, run a lint test on the Controller (php -l ControllerName.php) and if it fails then the problem is in your code.

2 likes
issa2012's avatar

heelp: eroor

ReflectionException (-1) Class Main does not exist

Route Route::get('/Main', 'Main@index');

Controllers

webservices-ca@outloook.com's avatar

Old post: But I decided to try and make some basic nested Controllers.

I simply overlooked the use App\Http\Controllers\Controller; line in my Controller.

My new file:

App\Http\Controllers\Cars\CarController.php

It complained that: Class 'App\Http\Controllers\Car\CarController' not found

I updated my route based on 'https://laravel.com/docs/5.8/controllers#controllers-and-namespaces':

Route::get('/company/cars', 'Cars\CarController@index');

It also complained that the App\Http\Controllers\Cars\Controller.php couldnt be found: This was funny because I should only depend on a single 'App\Http\Controllers\Controller.php' file

I then used this in the Car controller

use App\Http\Controllers\Controller;

This puts the Controller back into the mix

Note: To confirm I compared the default LoginController and found that it was in fact using...

use App\Http\Controllers\Controller;

...because it too was in a different nested namespace as:

namespace App\Http\Controllers\Auth;

Now I am able to use my nested controllers based on the Laravel documentation https://laravel.com/docs/5.8/controllers#controllers-and-namespaces

Please or to participate in this conversation.