1 month ago

Getting Error: Cannot declare class A because the name is already in use

Posted 1 month ago by spbaniya

In CustomServiceProvider I added following piece of code:

private function publishRoutes()
    private function publishWebRoutes()
        $this->loadRoutesFrom(__DIR__ . '/../../' . ucfirst($this->module) . '/routes/web.php');
    private function publishApiRoutes()
        $this->loadRoutesFrom(__DIR__ . '/../../' . ucfirst($this->module) . '/routes/api.php');
     * Load the standard routes file for the application.
     * @param string $path
     * @return mixed
    protected function loadRoutesFrom($path)
            // 'middleware' => 'api',
            'namespace' => 'Module\' . ucfirst($this->module) . '\Http\Controllers\',
            'prefix' => $this->module,
        ], function ($router) use ($path) {
            require $path;

I defined a route in web.php as

Route::get('test', '[email protected]');

When I tried to run, I'm getting this error:

Symfony\Component\Debug\Exception\FatalErrorExceptionCannot declare class Module\Account\Http\Controllers\AccountController, because the name is already in use

Any idea why am I getting this error? I have not declared AccountController anywhere else.. Also I get same error for any random Controller

Please sign in or create an account to participate in this conversation.