Search code examples
phplaravelmodel-view-controllerrouteslaravel-routing

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

Solution

  • Change you namespace to

    namespace App\Http\Controllers\AdminControllers;
    

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