问题
I recently migrated a laravel 4.2 project to 5.0. So far I have completed all the necessary steps but I keep getting an error.
Cannot declare class Controller, because the name is already in use
My Controller is changed as provided by laravel in the upgrade guide.
<?php
use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
abstract class Controller extends BaseController {
use DispatchesCommands, ValidatesRequests;
}
Also I have added it to the classmap directive of my composer.json.
"autoload": {
"classmap": [
"database",
"app/Http/Controllers"
],
"psr-4": {
"App\\": "app/"
}
},
I couldn't find any solution so far so if you guys know what to do it would help me out a lot :) thanks in advance!
回答1:
Remove the "app/Http/Controllers"
from your classmap.
Add namespace App\Http\Controllers;
above your use
blocks.
Then run composer dump-auto
回答2:
I'm pretty sure you have to add namespaces.
Namespacing
By default, Laravel 4 applications did not utilize namespacing within your application code. So, for example, all Eloquent models and controllers simply lived in the "global" namespace. For a quicker migration, you can simply leave these classes in the global namespace in Laravel 5 as well.
回答3:
When Creating Auto Discovery Events and their Listener classes, Just add below namespace at the top of your Listener class to avoid this error:
namespace App\Listeners;
回答4:
i had this problem on windows 2012 Server
when i use xdebug
i start debug and all worked good
there is no problem in my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
class HomeController extends BaseController
{
来源:https://stackoverflow.com/questions/40406418/cannot-declare-class-controller-because-the-name-is-already-in-use