0

after installing some packages in laravel we should add class definition to providers array. as you know we have this array:


'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    // ...
    App\Providers\AnnotationsServiceProvider::class,
    Collective\Html\HtmlServiceProvider::class,
],

my question is how can i add class to this array programical? does any ability in laravel to add it? for example:

App::install();
5
  • 2
    Laravel 5.5+ has automatic package discovery, meaning you don't need to add anything in the providers array. And you shouldn't change app.php in your code since it should be in your VCS and gets cached by the framework. Commented Jan 11, 2021 at 16:37
  • @Remul you suppose after installing nwdart we should add it to providers Commented Jan 11, 2021 at 16:40
  • No, for most packages you don't have to add anything to the providers array when installing it. Commented Jan 11, 2021 at 16:43
  • @Remul ok. now how can i add for some packages which should be added into this array? Commented Jan 11, 2021 at 16:54
  • You do it manually in that case. Commented Jan 12, 2021 at 8:14

1 Answer 1

1

If you're using a later or equal version of Laravel 5.5, you can use your package's composer.json file to register your classes automatically by using Laravel's package discovery feature:

"extra": {
    "laravel": {
        "providers": [
            "Foo\\Bar\\ServiceProvider"
        ],
        "aliases": {
            "Bar": "Foo\\Bar\\Facade"
        }
    }
}

to add providers and aliases into the application's runtime configuration. Many packages support it now without doing anything.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.