4

I upgraded my project from Laravel 4.2 to 5.0 but I get this error when I finish the process:

Class 'App\Http\Controllers\Controller' not found' in .../app/Http/Controllers/Auth/AuthController.php:8

But the mentioned controller is there, in app/Http/Controllers/Controller.php.

Also it is defined in composer.json, autoload, classmap:

"autoload": {
        "classmap": [
            "database",
            "app/Http/Controllers",
            "app/Libraries"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },

Apparently this is a namespace problem, but I don't know hot to solve it

Paulo Coghi
  • 13,724
  • 14
  • 68
  • 90

3 Answers3

3

In 99% of the cases the main cause of classes being not found when you migrate a Laravel 4 project to Laravel 5 is the lack of Namespaces

It is important to add namespaces to all your classes, controllers, old filters as middleware, etc.

Paulo Coghi
  • 13,724
  • 14
  • 68
  • 90
2

Just add the file/directory to your composer like that.

"autoload": { "classmap": [ "app/Http/Controllers/Controller.php" ],

There are a lot of other ways too. Or use psr-0,psr-4 to autoload the directory/file. Or you load this file in global.php.

Harry Geo
  • 1,163
  • 3
  • 10
  • 24
  • I already added "app/Http/Controllers" to classmap, in autoload. But, even when I add "app/Http/Controllers/Controller.php" it doesn't work – Paulo Coghi Mar 23 '15 at 14:29
  • What are the other ways? – Paulo Coghi Mar 23 '15 at 14:30
  • Did you do a *composer dump-autoload* first? When I refer to other ways are psr-0,psr-4 and global.php... You just really need to autoload the file and the class will exist in the Laravel main container. Try psr-4 and report back. ` "psr-4": { "MyNameSpace\\": "app\MyNameSpace" } ` – Harry Geo Mar 23 '15 at 14:44
  • Yes, I did a composer dump-autoload, and the error persists – Paulo Coghi Mar 23 '15 at 15:45
  • Did you set up your project name, incase you have, then [your project]/Http/Controllers/Controller; – UX Labs May 01 '15 at 11:18
2

I had the same problem. Following the upgrade guide (http://laravel.com/docs/5.0/upgrade#upgrade-5.0) the migration went fine but then when I started playing with Auth, I got the same error.

The reasons were that I followed the upgrade guide. When it says "Since we are not going to migrate to full namespacing in this guide", in fact you should use namespaces in your controllers with at their top

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

And then unwind what you did in the Controllers section of the upgrade guide. Then after running composer dump-autoload, it will work.

kintso
  • 248
  • 5
  • 15