Laravel 5 Unable to detect application namespace

前端 未结 6 906
灰色年华
灰色年华 2020-12-29 18:10

I\'m new to Laravel 5 and trying to understand it bit by bit and at the moment I\'m really confused with error messages. MVC is new thing to me.

What I\'m trying to

6条回答
  •  旧巷少年郎
    2020-12-29 18:24

    laravel version: 5.8.3

    [One more Reason]: default app path in composer.json is modified

    the default setup looks like this

    "psr-4": {
        "App\\": "app/"
     },
    

    If its modified to say,

    "psr-4": {
        "Core\\": "app/Core/"
     },
    

    the make commands with artisan wont work, and a few other things

    the reason is https://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/Application.php#L296

    app is static in the path, and here is the where the exception is thrown https://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/Application.php#L1143

    This default behavior can be modified in bootstrap/app.php

    Here is my solution [reference: https://laracasts.com/discuss/channels/general-discussion/how-i-can-change-laravel-directory-structure?page=1]

    Solution:

    Core/Application.php

    bootstap/app.php

    $app = new \Core\Application(
        $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
    );
    

提交回复
热议问题