Habib
Habib

Reputation: 601

laravel is giving error on custom controller used in routes

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";
    }
}

Upvotes: 0

Views: 341

Answers (3)

Roman Karki
Roman Karki

Reputation: 111

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;


Upvotes: 0

Saumya Rastogi
Saumya Rastogi

Reputation: 13693

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!

Upvotes: 1

scottevans93
scottevans93

Reputation: 1079

Change you namespace to

namespace App\Http\Controllers\AdminControllers;

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

Upvotes: 1

Related Questions