vikingcode
vikingcode

Reputation: 633

Laravel simply won't find my class

Laravel keeps telling me that my class isn't found and I'm pretty sure I've exhausted any solution.

Route:

Route::get('/custom-reports/timezone', array( 'uses' => 'Controllers\Reports\TimezoneController@generate'));

Directories:

app/controllers/Reports/TimezoneController.php

TimzoneController.php

<?php 
namespace Controllers\Reports;
use Controllers\BaseController;

class TimezoneController extends BaseController
{
    public function generate() {}
}

Composer.json:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/libraries",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/libraries/Illuminate/Cookie/Guard.php"
    ],
    "files": [
        "app/helpers.php"
    ]
},

Error:

ReflectionException -1
Class Controllers\Reports\TimezoneController does not exist

I have already done php composer dump-autoload

Upvotes: 0

Views: 311

Answers (1)

Marwelln
Marwelln

Reputation: 29443

classmap doesn't support namespacing (as far as I know) so you need to setup a PSR-4 autoloader.

Change your composer.json to this and run composer dump-autoload. It should work after that.

"autoload": {
    "classmap": [
        ...
    ],
    "files": [
        ...
    ],
    "psr-4": {
        "Controllers\\": "app/controllers"
    }
},

Upvotes: 1

Related Questions