phplaravelpackage-development

Laravel: Permanently override config of dependencies from a Laravel Package before publishing them


I am developing a Laravel Package which installs a list of dependencies. The dependencies have their own configuration files to be published after installation.

What we need is to auto (to avoid doing it manually) modify the config files of these dependencies by our package before/after publishing them and placing them in app/config.

I found some solutions like using mergeConfigFrom() in register method of Package's service provider. But it doesn't modify file content itself, just loads the merged config. We need to modify config file's content by the package that we developing so that we don't need to change config file manually after package installation.

For example, we install Laravel Horizon as a dependency the our package. Horizon publishes a config file called horizon.php in app/config. We need to auto modify some values for app/config/horizon.php before or after publishing that config file.

Any help will be much appreciated. Thanks :)


Solution

  • This is currently not possible. Look at Illuminate\Foundation\Console\VendorPublishCommand in the laravel framework source code.

    1. Best way to go is to completely replace horizon.php config in your package by publishing it on the same file.
    2. Alternativly you can write a custom command to inject this data in the horizon.php
    3. You could make a PR in laravel framework for you to allow this. and hope for the best they accept your PR.