laravel-route-attributes icon indicating copy to clipboard operation
laravel-route-attributes copied to clipboard

Cannot declare class because the name is already in use

Open tekord opened this issue 3 years ago • 2 comments

I have multiple directories with the Controller base class like that:

  • App\Modules\Admin
    • Controller
    • DashboardController
  • App\Modules\Api
    • Controller
    • UserController

When I specified all these directories in the 'directories' parameter (route-attributes.php file) I got the following error:

Cannot declare class App\Modules\Api\Controllers\Controller, because the name is already in use

So, it is impossible to use this package when an application has controller classes with the same name.

PHP 8.0.11 Laravel 8.64

tekord avatar Oct 15 '21 10:10 tekord

Trying to solve this issue I came up with the conclusion that there is not an error.

As the package has no tests, I created a project in order show that.

I was able to reproduce the error when the Controllers have the same name and the same namespace. Anyway, this is expected and not an issue itself.

sebapastore avatar Jan 26 '22 01:01 sebapastore

Yes it just means you messed up the namespace, you copied App\Modules\Api\Controller\Controller.php to App\Modules\Admin\Controller\Controller.php without changing the namespace (Happens to all of us)

If you look in App\Modules\Admin\Controller\Controller.php

You'll see namespace App\Modules\Api\Controller and this is why php is throwing an error

There is no issue in the package here

Tofandel avatar Aug 09 '22 11:08 Tofandel