Back

Namespacing behaving strangely after upgrade to 5.1 from 4.2


I am trying to update our application to Laravel 5.1 from 4.2. We are going for a full upgrade from the start. We were using psr-4 namespaces in 4.2 so this wasn't expected to fail nor we were able to find its origin either, all seems fine. All our endpoints (domains, we have 4 in total) are facing the same issue on accessing any route.

App Directory Structure

Console
    Commands
        BackTools
        Consumer
        [Other Endpoints]
Events
Exceptions
Http
    Controllers
        BackTools
        Consumer
        [Other Endpoints]
    Middleware
        BackTools
        Consumer
        [Other Endpoints]
    Requests
    Routes
        BackTools
        Consumer
        [Other Endpoints]
    ViewComposers
        BackTools
        Consumer
        [Other Endpoints]
Jobs
    BackTools
    Consumer
    [Other Endpoints]
Libraries
Listeners
Providers

Routes

Route::group(array(
    'domain' => Config::get('settings.domains.back'),
    'middleware' => 'back.auth'
), function () {

    Route::group(array('namespace' => 'back\\controllers\\'), function () {
        Route::get('', array('as' => 'back.home', 'uses' => '[email protected]'));
        Route::post('send-custom-emails',
            array('as' => 'back.sendCustomEmails', 'uses' => '[email protected]'));
        });
});

Composer

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "companyX\\": "app/",
        "back\\composers\\": "app/Http/ViewComposers/BackTools",
        "back\\controllers\\": "app/Http/Controllers/BackTools",
        "back\\jobs\\": "app/Jobs/BackTools",
        "back\\middleware\\": "app/Http/Middleware/BackTools",
        "consumer\\composers\\": "app/Http/ViewComposers/Consumer",
        "consumer\\controllers\\": "app/Http/Controllers/Consumer",
        "consumer\\jobs\\": "app/Jobs/Consumer",
        "consumer\\middleware\\": "app/Http/Middleware/Consumer",          
        "companyX\\commands\\": "app/Console/Commands",
        "companyX\\composers\\": "app/ViewComposers",
        "companyX\\controllers\\": "app/Http/Controllers",
        "companyX\\jobs\\": "app/Jobs",
        "companyX\\libraries\\": "app/Libraries",
        "companyX\\providers\\": "app/Providers"
    }
},

Autoload Classmap After Optimize

'back\\controllers\\AuthController' => $baseDir . '/app/Http/Controllers/BackTools/AuthController.php',
'back\\controllers\\BackToolsController' => $baseDir . '/app/Http/Controllers/BackTools/BackToolsController.php',

Example Error

ReflectionException in Container.php line 736: Class swaggable\Http\Controllers\back\controllers\BackToolsController does not exist

What Has Been Tried Yet

  • clearing all caches
  • regenerating auto load files
brazenvoid replied 3 years ago

Found the issue. Change $namespace to '' in RouteServiceProvider.


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us