4
votes

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

3

3 Answers

3
votes

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.

2
votes

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.

2
votes

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.