#Can I use my custom package to override another packages config?

5 messages · Page 1 of 1 (latest)

sleek rock
#

I am trying to learn and experiment with Laravel, mostly to upskill myself and I was wondering if you could make a fully modular monolith using composer packages.

So far its working great for me however I was wondering if its possible to override another packages Config from a given package?

For example (and just an example, I know it would be a ridiculous thing to do), right now in app/config/queue.php you can change the failed_jobs table name to whatever you want.

Is it possible, in my own custom package, to create a config file that would override this config? Allowing me to set it to whatever I want if my package is installed? For example, change the name to system_jobs_failed?

(note: I understand in this example I would need to change the migration script for this to actually work, I am more interested in writing packages that alter config settings.)

solar sphinx
# sleek rock I am trying to learn and experiment with Laravel, mostly to upskill myself and I...

Achieving full modularity is hard, you have to have an interface layer of classes that handle the integration in the application where you can do things like override values from other configs if you like. This is because to be fully modular one package (module) has to be agnostic of all others meaning they shouldn’t require knowledge of them, they should be independent entities that then only interact in the integration layer of your application. This is so a module can be installed into another application without needing the presence of other modules that are dependancies of themselves. There is a laravel a fair few open source laravel apps (mainly CMS’s) that have achieved full modularity so you can turn on/off features etc. I suggest jumping on GitHub and taking a look at modular laravel CMS’s. Might help you out.

sleek rock
#

Thanks for input @solar sphinx, I was starting to come to the realisation that that would be the case.

#

I suppose anything is possible depending on how far one is willing to customise

solar sphinx
# sleek rock I suppose anything is possible depending on how far one is willing to customise

Yeah if you don’t care about full modularity & are just using the packages to bundle your code for better DX & they will really only be specific to this app then you can really do whatever you need. You could have one package using the —force flag to overwrite a file that has been published from another config too. I found this post that might help: https://stackoverflow.com/questions/63907662/how-can-i-make-the-package-config-merge-its-non-existing-keys-into-the-app-conf - it’s not exactly what you want to do but shows what’s possible.