0

I have a simple in routes/web.php file

Route::get(Config::get('constants.ADMIN_PATH') . '/categories', 'AdminControllers\AdminPagesController@index');

I have made a folder AdminControllers and inside that there is a controller named AdminPagesController but i am getting error as

Class App\Http\Controllers\AdminControllers\AdminPagesController does not exist

Whereas i looked into the same folder and class exist. Here is my class code

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminPagesController extends Controller
{
    public function __construct() {

    }

    public function index () {
        return "hello";
    }
}
Habib
  • 591
  • 8
  • 29

3 Answers3

1

Change you namespace to

namespace App\Http\Controllers\AdminControllers;

Laravel will resolve controllers based on your name spacing, not on your directory structure.

scottevans93
  • 1,119
  • 1
  • 9
  • 25
1

You should specify the namespace correctly, change it to:

namespace App\Http\Controllers\AdminControllers; // <------- correct this namespace

use Illuminate\Http\Request;

class AdminPagesController extends Controller
{
    public function __construct() {

    }

    public function index () {
        return "hello";
    }
}

Hope this helps!

Saumya Rastogi
  • 13,159
  • 5
  • 42
  • 45
0

If you choose to nest your controllers deeper into the **

App\Http\Controllers


** directory, use the specific class name relative to the

App\Http\Controllers

root namespace.

namespace App\Http\Controllers\AdminControllers;


Roman Karki
  • 101
  • 6