Laravel Class 'App\Modules\ServiceProvider' not found?

前端 未结 8 1393
暗喜
暗喜 2021-01-01 19:39

Hello Friends I am new in Laravel framework.

i create modules directory in app folder.

then i also create ServiceProvider.php file in modules directory.

相关标签:
8条回答
  • 2021-01-01 20:22

    I'm pretty newbie in creating a package. The first time after I created the following structure, I put it in Vendor folder.

    qplot
        environment-color
            src
                config
                QPlot
                    EnvironmentColor
                        ColorServiceProvider.php
                        EnvironmentColor.php
            tests
    

    But soon I realized this doesn't make sense, since Laravel won't autoload all the bundles for you unless you registered it. So I moved folder to /app/vendor (new folder).

    And then following Andreyco's suggestion to notify autoload path

    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/vendor",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    

    And then when I run php artisan dump-autoload, and open vendor/composer/autoload_classmap.php, all new classes under QPlot are registered :)

    Now when I go back to add the provider to Laravel /app/config/app.php,

    'providers' => array(
        'QPlot\EnvironmentColor\ColorServiceProvider'
    

    So the steps are

    • setup your package in a folder where your git will cover
    • register the autoload in composer
    • composer dump-autoload
    • add provider to config
    • now go back to coding
    0 讨论(0)
  • 2021-01-01 20:24

    Add this to composer.json autoload section:

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

    and then composer dump-autoload

    0 讨论(0)
提交回复
热议问题